从文档中我找到了这段代码:
let jane: MyPersonEntity = // ...
CoreStore.perform(
asynchronous: { (transaction) -> Void in
// WRONG: jane.age = jane.age + 1
// RIGHT:
let jane = transaction.edit(jane)! // using the same variable name protects us from misusing the non-transaction instance
jane.age = jane.age + 1
},
completion: { _ in }
)
不知道为什么我们需要这样做// using the same variable name protects us from misusing the non-transaction instance
迅速建议我使用其中两个: