Created
October 8, 2013 14:14
-
-
Save alexrepty/6885366 to your computer and use it in GitHub Desktop.
Notification Inheritance Issues
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
#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