ios – 核心数据 – 保存上下文后撤消更改

ios – 核心数据 – 保存上下文后撤消更改,第1张

概述我最近注意到Core Data中的撤销机制这个奇怪的事情,从那以后它一直困扰着我. 引用来自NSManagedObjectContext文档的-undo方法: Sends an undo message to the receiver’s undo manager, asking it to reverse the latest uncommitted changes applied to obj 我最近注意到Core Data中的撤销机制这个奇怪的事情,从那以后它一直困扰着我.

引用来自NSManagedobjectContext文档的-undo方法:

Sends an undo message to the receiver’s undo manager,asking it to reverse the latest uncommitted changes applIEd to objects in the object graph.

要扭转最新的未提交更改,听起来很简单吧?

但是,实际情况并非如此!即使我使用托管对象上的更改保存上下文,以下-undo调用仍将成功撤消更改.这不是针对文档中陈述的内容吗?

也许我做错了什么?如果需要,我可以发布我的小测​​试代码.我真的很困惑.

解决方法 你应该感到困惑.核心数据文档是一个热点.他们使用了许多像“未提交”这样的词,这些词可能是不合适的.它们似乎意味着当它们说“未提交”时,其属性isFaulted等于NO的对象.

核心数据编程指南更详细:

Change and Undo Management

A context keeps strong references to managed objects that have pending
changes (insertions,deletions,or updates) until the context is sent
a save:,reset,rollback,or dealloc message,or the appropriate
number of undos to undo the change.

The undo manager associated with a context keeps strong references to
any changed managed objects. By default,in OS X the context’s undo
manager keeps an unlimited undo/redo stack. To limit your
application’s memory footprint,you should make sure that you scrub
(using removeAllActions) the context’s undo stack as and when
appropriate. Unless you keep a strong reference to a context’s undo
manager,it is deallocated with its context.

文档中的措辞/词汇不清晰或不一致.我相信,在适合您的应用程序时,您应该在上下文的undoManager属性上调用removeAllActions,以避免无限的内存增长.

总结

以上是内存溢出为你收集整理的ios – 核心数据 – 保存上下文后撤消更改全部内容,希望文章能够帮你解决ios – 核心数据 – 保存上下文后撤消更改所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1099225.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存