在Core Data中获取NSManagedObject的修改日期? [英] Get modification date for NSManagedObject in Core Data?
问题描述
除了在我的Core Data存储中为每个Entity添加一个NSDate属性外,是否有一个编程方式来获取任何对象的修改日期?
Outside of adding an NSDate property to each Entity in my Core Data store, is there a programmatic way to get the modification date for any object?
推荐答案
不,您必须添加日期并自行管理。您可以在受管对象中使用覆盖 -willSave
更新时间戳,但请阅读 -willSave $ c $上的NSManagedObject的API文档c>如何更新而不引起一个willSave循环(文档甚至谈论更新时间戳的情况)。文档还提到使用
NSManagedObjectContextWillSaveNotification
,但是设置起来可能比简单的检查更麻烦,不能太快地设置时间戳。
No, you must add a date and manage it yourself. You can use override -willSave
in your managed object to update the time stamp, but read the API documentation for NSManagedObject on -willSave
for how to update without causing a willSave loop (the docs even talk about the case of updating a timestamp). The docs also mention using the NSManagedObjectContextWillSaveNotification
, but that may be more trouble to set up than a simple check to not set the timestamp too quickly.
这篇关于在Core Data中获取NSManagedObject的修改日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!