Created
November 6, 2010 16:40
-
-
Save leviathan/665526 to your computer and use it in GitHub Desktop.
A category to send NSNotifications in the UI thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NSNotificationCenter+MainThread.h | |
@interface NSNotificationCenter (MainThread) | |
- (void)postNotificationOnMainThread:(NSNotification *)notification; | |
- (void)postNotificationOnMainThreadName:(NSString *)aName object:(id)anObject; | |
- (void)postNotificationOnMainThreadName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo; | |
@end | |
// NSNotificationCenter+MainThread.m | |
#import "NSNotificationCenter+MainThread.h" | |
@implementation NSNotificationCenter (MainThread) | |
- (void)postNotificationOnMainThread:(NSNotification *)notification { | |
[self performSelectorOnMainThread:@selector(postNotification:) withObject:notification waitUntilDone:YES]; | |
} | |
- (void)postNotificationOnMainThreadName:(NSString *)aName object:(id)anObject { | |
NSNotification *notification = [NSNotification notificationWithName:aName object:anObject]; | |
[self postNotificationOnMainThread:notification]; | |
} | |
- (void)postNotificationOnMainThreadName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo { | |
NSNotification *notification = [NSNotification notificationWithName:aName object:anObject userInfo:aUserInfo]; | |
[self postNotificationOnMainThread:notification]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment