NSOperation completionBlock保留循环警告?

时间:2017-05-19 03:50:50

标签: ios objective-c xcode nsoperation retain-cycle

我在我的应用程序的两个部分中有类似的代码,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"
        ...
    }
};

documentation说:

  

在iOS 8及更高版本和macOS 10.10及更高版本中,此属性设置为   完成块开始执行后为零。

所以我认为不会有任何保留周期。

0 个答案:

没有答案