Last active
September 30, 2019 12:56
-
-
Save bouchtaoui-dev/378525f79c0f675d6762dfdb5d0af49f to your computer and use it in GitHub Desktop.
NSNotification example
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
- (void) subscribeNotificationWithName: (NSString*) name { | |
[ [NSNotificationCenter defaultCenter ] addObserver: self | |
selector: @selector(didReceiveNotification:) | |
name: name | |
object: nil ]; | |
} | |
- (void) didReceiveNotification: (NSNotification *) notification { | |
NSLog(@"didReceiveNotification"); | |
NSString *title = (NSString*)notification.object; | |
NSDictionary *info = notification.userInfo; | |
NSString *message = [info objectForKey: @"error.message"]; | |
} | |
- (void) postNotification { | |
NSDictionary *info = [NSDictionary dictionaryWithObject: ErrorMessage | |
forKey: @"error.message"]; | |
[[NSNotificationCenter defaultCenter] postNotificationName: @"some message" | |
object: @"Connection Status" | |
userInfo: info]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment