为每个动作保存上下文

Saving context for every action

我有我的应用程序的网络公园,它发现网络中的设备并通过 Magical Record 插入到核心数据中。但这是在其他线程而不是主线程上发生的。我还有带 fetchresultcontroller 的 UITableView,它在 table 视图中显示设备。但唯一的选择是如何让 fetchRequestController 现在了解我的更改,调用这个:

[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreAndWait];

每次更改后。缺少我的东西,或者这是正确的制作方法?

示例:

[MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext){
    MyCDDevice * localDevice = [MyCDDevice MR_createEntityInContext:localContext];
    [localDevice initFromDictionary:dictionary];
}];

[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreAndWait];

节省每个整体数据操作,这是MagicalRecord推荐的。 saveWithBlockAndWait:后保存到persistent store,所以不需要MR_saveToPersistentStoreAndWait.