片段一、二
@interface XLViewController ()
@property (nonatomic, copy) void (^testBlock)();
@property (nonatomic, copy) void (^anotherTestBlock)(XLViewController *controller);
@end
@implementation XLViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// 片段一
WeakObj(self);
self.testBlock = ^ {
StrongObj(self);
[strongself doSomething];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_global_queue(0, 0), ^{
[strongself doAnotherThing];
});
};
self.testBlock();
// 片段二
self.anotherTestBlock = ^(XLViewController *controller){
[controller doSomething];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_global_queue(0, 0), ^{
[controller doAnotherThing];
});
};
self.anotherTestBlock(self);
}
- (void)doSomething {
NSLog(@"doSomething");
}
- (void)doAnotherThing {
NSLog(@"doAnotherThing");
}
- (void)dealloc {
NSLog(@"-- XLViewController -- dealloc --");
}
@end