微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我最近注意到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,以避免无限的内存增长.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐