Skip to content

Instantly share code, notes, and snippets.

@alexrepty
Created October 8, 2013 14:14
Show Gist options
  • Save alexrepty/6885366 to your computer and use it in GitHub Desktop.
Save alexrepty/6885366 to your computer and use it in GitHub Desktop.
Notification Inheritance Issues
#import <Foundation/Foundation.h>
NSString *const kNotificationName = @"NotificationName";
@interface Foobar : NSObject
@end
@implementation Foobar
- (id)init {
self = [super init];
if(self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(trollolo:) name:kNotificationName object:nil];
}
return self;
}
- (void)trollolo:(NSNotification *)notification {
NSLog(@"Foobar: %@", NSStringFromClass([self class]));
}
@end
@interface SubFoobar : Foobar
@end
@implementation SubFoobar
- (id)init {
self = [super init];
if(self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(trollolo:) name:kNotificationName object:nil];
}
return self;
}
- (void)trollolo:(NSNotification *)notification {
NSLog(@"SubFoobar: %@", NSStringFromClass([self class]));
}
@end
int main(int argc, char *argv[]) {
NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
Foobar *foobar = [[Foobar alloc] init];
SubFoobar *subFoobar = [[SubFoobar alloc] init];
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationName object:nil];
[p release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment