开发者

Multi-property "transactions" in Core Data / NSManagedObject / NSFetchedResultsController?

Is it possible to set multiple properties of an NSManagedObject and have t开发者_高级运维he NSFetchedResultsController call controllerDidChangeContent: only once?

In other words, is it possible to say something like:

[managedObject beginChanges];
[managedObject setPropertyA:@"Foo"];
[managedObject setPropertyB:@"Bar"];
[managedObject commitChanges];

and then have the NSFetchedResultsController call controllerDidChangeContent: (and the other methods) only one time?

Thanks!


I'm solving it now by creating another NSManagedObjectContext, that acts as 'scratch pad' for the changes. Then when all edits have been done, it's merged back into the other context, using mergeChangesFromContextDidSaveNotification:. There is a sample project called CoreDataBooks showing how this works.


While definitely not a perfect solution, you could add a method to your managed object class that takes the two new property values, and works much like your code above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜