Tuesday, August 5, 2014

[iOS]Ojbective C async call sample

1. Define block method:
typedef void (^MyTestBlock)(void);

MyTestBlock myBlock = ^void() {
    // your implementation
}];

2. Consumer
[[NSNotificationCenter defaultCenter] addObserverForName:@"key" object:nil queue:nil usingBlock:^(NSNotification *note) {
            myBlock();
        }];

3. Trigger
[[NSNotificationCenter defaultCenter] postNotificationName:@"key" object:nil userInfo:nil];

No comments:

Post a Comment