我在我的应用程序的两个部分中有类似的代码,xcode为一个而不是另一个提供警告。根据我对文档的理解,我认为在任何一种情况下都不应该发出警告。
// In one part of my code I have this
__block UploadOperation *uploadOperation = [[UploadOperation alloc] initWithPsc:self.persistentStoreCoordinator webService:self.webService];
uploadOperation.completionBlock = ^{
if (uploadOperation.uploadCount > 0) {
self.expediteNextSync = YES;
}
};
// And in another I have this
__block SyncOperation *syncOperation = [[SyncOperation alloc] initWithPsc:self.persistentStoreCoordinator webService:self.webService];
syncOperation.completionBlock = ^{
if (syncOperation.expediteNextSync) { // <--- This one gives the warning "Capturing 'syncOperation' strongly in this block is likely to lead to a retain cycle"
...
}
};
在iOS 8及更高版本和macOS 10.10及更高版本中,此属性设置为 完成块开始执行后为零。
所以我认为不会有任何保留周期。