多财产“交易”在核心数据/ NSManagedObject / NSFetchedResultsController 中?
是否可以设置 NSManagedObject 的多个属性并让 NSFetchedResultsController 调用controllerDidChangeContent: 一次?
换句话说,是否可以这样说:
[managedObject beginChanges];
[managedObject setPropertyA:@"Foo"];
[managedObject setPropertyB:@"Bar"];
[managedObject commitChanges];
然后让 NSFetchedResultsController 调用controllerDidChangeContent:(以及其他方法)一次?
谢谢!
Is it possible to set multiple properties of an NSManagedObject and have the 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我现在通过创建另一个 NSManagedObjectContext 来解决这个问题,它充当更改的“便笺簿”。然后,当所有编辑完成后,它会使用
mergeChangesFromContextDidSaveNotification:
合并回其他上下文。有一个名为 CoreDataBooks 的示例项目展示了其工作原理。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, usingmergeChangesFromContextDidSaveNotification:
. 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.