#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *lblName;
@end
@implementation ViewController
- (IBAction)addObserver:(id)sender {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(printName:) name:@"printName" object:nil];
}
- (IBAction)PostNotification:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:@"printName" object:@"NiKlaus"];
}
- (IBAction)removeObserver:(id)sender {
[[NSNotificationCenter defaultCenter] removeObserver:self];
dispatch_async(dispatch_get_main_queue(), ^{
self.lblName.text = @"NAME";
});
}
- (void) printName:(NSNotification*) notification {
id name = [notification object];
dispatch_async(dispatch_get_main_queue(), ^{
self.lblName.text = name;
});
}
@end