CoreData: How to sort NSManagedObject by its primary key?

后端 未结 2 1884
心在旅途
心在旅途 2021-01-14 01:02

I have one subclass of NSManagedObject like following and stored some instances by NSManagedObjectContext.

@interface SomeModelObject : NSManagedObject  
  @prop         


        
2条回答
  •  生来不讨喜
    2021-01-14 01:36

    Given that the primary key is an opaque data type whose value is an arbitrary implementation detail completely outside of your control (including potentially not being constant over time), it seems non-sensical to want to sort by it.

    If you are looking for a stable, determined, order, then -- yes -- sort by a different attribute, either an existing one or a new one.

    Note that, in general, it is best to not think of Core Data in relational database terms. Focus on the object graph and object modeling aspects as that is what the APIs are focused upon.

提交回复
热议问题