#pragma mark -- 循环引用 //----------------------------------------------------------------------------------------------------
/*
某些block中,使用self会造成循环引用
__weak AppDelegate *weakSelf = self;
dispatch_async(mainQueue, ^(void) {
AppDelegate *strongSelf = weakSelf;
if (strongSelf != nil){
[strongSelf.myTimer invalidate];
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskIdentifier];
strongSelf.backgroundTaskIdentifier = UIBackgroundTaskInvalid;
}
});
__unsafe_unretained contentsViewController* yqContentsViewController = self;
[_threeView reminderBlock:^{
[_alertView setMessage:@"本章节内容暂时为空"];
[_alertView show];
[NSTimer scheduledTimerWithTimeInterval:1.0f target:yqContentsViewController selector:@selector(alertDismissed) userInfo:nil repeats:NO];
}];
*/
本文探讨了在iOS开发中如何避免block内部使用self导致的循环引用问题,并提供了两种实用的方法:使用__weak指针和__unsafe_unretained指针。
697

被折叠的 条评论
为什么被折叠?



