我試圖創建一個回調,在發生故障延遲後重試該方法。我正在發出此警告:阻止將自身作爲引發編譯器警告的方法的參數
「在此塊中強烈捕獲故障塊可能會導致保留週期。」
typedef void (^MyCallbackBlock)(NSObject *);
...
__block MyObject *blockSelf = self;
__block MyCallbackBlock successBlock = ^(NSObject *someObject)
{
// To be completed
};
__block MyCallbackBlock failureBlock = ^(NSObject *someObject)
{
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[blockSelf doSomething:someObject onSuccess:successBlock onFailure:failureBlock]; // <-- Warning is here
});
};
[blockSelf doSomething:someObject onSuccess:successBlock onFailure:failureBlock];
...
- (void)doSomething:(NSObject *)someObject
onSuccess:(MyCallbackBlock)successBlock
onFailure:(MyCallbackBlock)failureBlock;
問題:如何使這項工作正常進行?
(我一直在讀通過其他SO問題 - 還沒有找到一個匹配的是,雖然不會感到驚訝,如果一個人在那裏)
這可能是答案,給它一個嘗試:http://stackoverflow.com/questions/7205128/fix-warning-capturing-an-object-strongly-in-this-block-is-likely-to-導致一 – 2013-05-01 20:27:58