I have one subclass of NSManagedObject like following and stored some instances by NSManagedObjectContext.
@interface SomeModelObject : NSManagedObject @property (nonatomic, retain) NSString * text; @end
Now, I want to fetch the list sorted by its primary key (created automatically). I've tried NSFetchRequest and got runtime error: "keypath id not found in entity".
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SomeModelObject" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"id" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sort, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
Is it possible to sort by primary key? Or should I add some column to Model class for sorting?