我有一个 NSObject 类别可以在一段时间后执行块。在这种情况下我需要弱化自我吗?
__weak ViewController *weakSelf = self;
[self runBlockAfterDelay:0.6 block:^{
weakSelf.someview = ...
}];
// Category
- (void)runBlockAfterDelay:(NSTimeInterval)delay block:(void (^)(void))block {
dispatch_async(dispatch_get_main_queue(), ^{
[self performSelector:@selector(executeBlockAfterDelay:) withObject:[block copy] afterDelay:delay];
});
}
- (void)executeBlockAfterDelay:(void(^)(void))block
{
if (block)
block();
}