CoreData: How to sort NSManagedObject by its primary key?

后端 未结 2 1887
心在旅途
心在旅途 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:54

    Use a sort descriptor with self as the sort key (instead of id). The underlying SQL will have ORDER BY t0.Z_PK.

    Warning: as mentioned by vastopa below this is undocumented and crashes in iOS 10, and there is also a non-null probability that this breaks in a future version of iOS, so use at your own risk.

提交回复
热议问题