我有一个NSOperation的子类,我想做这样的事情:
@interface MyOperation : NSOperation...
MyOperation *myOperation = [[MyOperation alloc] init];
[myOperation setCompletionBlock = [^{
[myOperation doSomething]; // Do something with myOperation and other classes captured from original environment
[myOperation setCompletionBlock:nil]; // Manually setting to nil avoid retain cycles;
} copy]; <- is this "copy" needed here?
因此,我对此代码的问题是标题问题:
我是否需要将传递给setCompletionBlock的块复制(Block_copy()):或NSOperation会为我做这件事?
最佳答案
从-[NSOperation setCompletionBlock:] reference:
操作完成时要执行的块。此方法创建指定块的副本。块本身不应该有任何参数,也没有返回值。
所以不,您不需要复制块,因为NSOperation已经为您完成了此操作。
关于objective-c - 我是否需要Block_copy我传递给NSOperation的setCompletionBlock的块?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16199435/