Created
November 12, 2014 23:48
-
-
Save caoer/770a9cd83ddb026911de to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| for (int i = 0; i < 30; i++) { | |
| __block __weak id ob1 = nil; | |
| __block __weak id ob2 = nil; | |
| void (^block)(NSNotification *) = ^(NSNotification *note) { | |
| NSLog(@"got noti %@, ob1: %@, ob2: %@", note.name, ob1, ob2); | |
| [[NSNotificationCenter defaultCenter] removeObserver:ob1]; | |
| [[NSNotificationCenter defaultCenter] removeObserver:ob2]; | |
| }; | |
| ob1 = [[NSNotificationCenter defaultCenter] addObserverForName:@"obbb1" object:nil queue:nil usingBlock:block]; | |
| ob2 = [[NSNotificationCenter defaultCenter] addObserverForName:@"obbb2" object:nil queue:nil usingBlock:block]; | |
| dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(arc4random() % 1000 / 50.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
| int k = arc4random() % 100; | |
| NSLog(@"k %d", k); | |
| if (k > 50) { | |
| NSLog(@"post obbb1"); | |
| [[NSNotificationCenter defaultCenter] postNotificationName:@"obbb1" object:nil]; | |
| } | |
| else { | |
| NSLog(@"post obbb2"); | |
| [[NSNotificationCenter defaultCenter] postNotificationName:@"obbb2" object:nil]; | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment