我有一些typedef:
typedef void (^myBlock)(SomeObject);
我有一些对象
@interface SomeObject : NSObject
@end
// Method of some arbitrary class
- (void) someMethod1 {
SomeObject *someObject = [[SomeObject alloc] init];
myBlock block = ^(SomeObject obj){
// When _block(someObject)_ will be called inside someQueue -
// Is it guaranteed that someObject will be alive, retained inside me?
// Do something complex and involving (or not) obj ...
}
dispatch_async(someQueue, ^{
// Some bunch of code - after which we are sure that
// by the next line someMethod1 will run out, so its scope is lost
block(someObject);
});
}
问题放在块变量的块中:是否保证我们传递给 someQueue 队列中的块块的 someObject 对象将是活动的并保留在块块中?
这个问题是我刚刚提出的问题的一个更复杂的变体:将对象传递到块是否保证其生命周期将被保留?.