我正在使用多線程/ NSManagedObjectContexts的對象導入功能,使用http://www.mac-developer-network.com/columns/coredata/may2009/作爲我的指南(請注意,我正在爲iPhone開發)。爲什麼可以在沒有顯式合併的情況下從一個NSManagedObjectContext填充更改到另一個?
出於某種原因,當我保存其中一個上下文時,其他人立即更新了更改,即使我已將註釋掉了對mergeChangesFromContextDidSaveNotification的調用。沒有任何明確的呼叫,上下文可能合併到另一箇中是否有任何原因?
這裏日誌是怎麼回事:
// 1.) Main context is saved with "Peter Gabriel"
// 2.) Test context is created, begins with same contents as main context
// 3.) Main context is inserted with "Spoon"
// 4.) Test context is inserted with "Phoenix"
// Contents at this point:
CoreTest[4341:903] Artists in main context: (
"Peter Gabriel",
"Spoon"
)
CoreTest[4341:903] Artists in test context: (
"Peter Gabriel",
"Phoenix"
)
// 5.) testContext is saved
// New contents of contexts:
CoreTest[4341:903] Artists in main context: (
"Peter Gabriel",
"Phoenix",
"Spoon"
)
CoreTest[4341:903] Artists in test context: (
"Peter Gabriel",
"Phoenix"
)
正如你所看到的,測試上下文中途保存,並且主要方面突然有從測試方面的新對象,即使我的避風港不執行整個NSManagedObjectContextDidSaveNotification/mergeChangesFromContext組合。
我的理解是,除非明確做到,否則任何更改都不會合並......有人知道這裏發生了什麼嗎?
這很有道理......感謝您的糾正! – 2010-03-19 07:55:21