Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

50 lines (38 sloc) 2.272 kB
#import "NSNotificationAdditions.h"
#import <pthread.h>
@implementation NSNotificationCenter (NSNotificationCenterAdditions)
- (void) postNotificationOnMainThread:(NSNotification *) notification {
if( pthread_main_np() ) return [self postNotification:notification];
[self postNotificationOnMainThread:notification waitUntilDone:NO];
}
- (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait {
if( pthread_main_np() ) return [self postNotification:notification];
[[self class] performSelectorOnMainThread:@selector( _postNotification: ) withObject:notification waitUntilDone:wait];
}
+ (void) _postNotification:(NSNotification *) notification {
[[self defaultCenter] postNotification:notification];
}
- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object {
if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:nil];
[self postNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO];
}
- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo {
if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo];
[self postNotificationOnMainThreadWithName:name object:object userInfo:userInfo waitUntilDone:NO];
}
- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait {
if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo];
NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithCapacity:3];
if( name ) [info setObject:name forKey:@"name"];
if( object ) [info setObject:object forKey:@"object"];
if( userInfo ) [info setObject:userInfo forKey:@"userInfo"];
[[self class] performSelectorOnMainThread:@selector( _postNotificationName: ) withObject:info waitUntilDone:wait];
[info release];
}
+ (void) _postNotificationName:(NSDictionary *) info {
NSString *name = [info objectForKey:@"name"];
id object = [info objectForKey:@"object"];
NSDictionary *userInfo = [info objectForKey:@"userInfo"];
[[self defaultCenter] postNotificationName:name object:object userInfo:userInfo];
}
@end
Jump to Line
Something went wrong with that request. Please try again.