我有一个看起来像这样的方法:
- (void)doSomething:(void(^)(MyItem *item))optionalBlock {
// 1. Do the regular stuff with the item
item.regularStuff = @"something_regular";
// 2. Run the optional block
// which may or may not make some extra modifications to the item
if (optionalBlock) optionalBlock(item);
// 3. Save the modified item into the Core Data
// etc
}
我打算这样调用它
[self doSomething:nil];
或者:
[self doSomething:^(MyItem *item) {
// Make some extra modifications to the item before it’s saved
item.custom = @"custom";
}];
是否可以安全地假设在第三步中我总是会获得已被方法和(可能)可选 block 修改的item
,或者我是否需要实现某种有一种方法可以准确地找出 block 何时完成执行,以便我可以从那里继续?
最佳答案
很安全。你不需要任何特殊检查。
关于objective-c - 方法中间的可选 block : safe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14049470/