【发布时间】:2016-10-30 09:05:48
【问题描述】:
假设如下情况:
self.collectionViewController.didEndDisplayingCell = ^(CollectionViewCell *cell) {
[self doSomething];
};
Xcode 会抱怨我不能在该方法中使用 self ,否则我将有一个保留周期。
然后是另一种情况。我创建了一个类,它加载图像并在完成时运行某些东西并调用它
[[MyImageClass sharedInstance] loadImageFromUrl:url
runOnCompletion:^(UIImage *image) {
[self doSomething];
}];
Xcode 在这种情况下不会报错,并且 self 在块内使用!
为什么?
【问题讨论】:
标签: ios iphone memory-leaks objective-c-blocks