【问题标题】:Is there an difference between transient properties defined in the data model, or in the custom subclass of NSManagedObject?在数据模型或 NSManagedObject 的自定义子类中定义的瞬态属性之间是否有区别?
【发布时间】:2011-03-01 02:02:06
【问题描述】:

我在读到设置瞬态属性的值总是会导致将托管对象标记为“脏”。但是,我没有得到的是:如果我创建 NSManagedObject 的子类并使用一些我不需要持久化的额外属性,Core Data 如何知道它们以及它如何将对象标记为脏我访问这些?

同样,它们没有在数据模型中定义,因此 Core Data 并没有很好地暗示它们存在。

或者 Core Data 是否使用某种自省来分析我的自定义类并找出我在其中有哪些属性?

【问题讨论】:

    标签: iphone core-data


    【解决方案1】:
    NSManagedObject
    /*  Distinguish between changes that should and should not dirty the object for any key unknown to Core Data.  10.5 & earlier default to NO.  10.6 and later default to YES. */
    /*    Similarly, transient attributes may be individually flagged as not dirtying the object by adding +(BOOL)contextShouldIgnoreChangesFor<key> where <key> is the property name. */
    + (BOOL)contextShouldIgnoreUnmodeledPropertyChanges NS_AVAILABLE(10_6,3_0);
    

    瞬态属性可以由撤消/重做管理器处理,额外的属性不能。

    我发现核心数据“脏”制定规则的一些奇怪行为:

    在 iOS 5 上,在 -(void)didSave 中设置瞬态属性会使上下文变脏,但在 iOS 4.3 上则不会。

    how to make NSManagedObjectContext dirty (hasChanges = YES) Manually

    我不认为核心数据可能会反省您NSManagedObjects 的自定义子类

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-17
      • 2019-12-14
      • 2018-09-05
      • 2013-04-21
      • 1970-01-01
      • 2014-09-01
      • 1970-01-01
      • 2018-07-30
      相关资源
      最近更新 更多