我有一个看起来像这样的方法:
- (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";
}];
是否可以安全地假设在第三步我总是会得到item
已经被方法和(可能)可选块修改的,或者我是否需要实现某种方法来准确找出块何时完成执行所以我可以从那里继续?