简体   繁体   中英

Sorting by a dictionary key with NSFetchedResultsController

I have a NSManagedObjectContext whose model defines five keys: GUID, Parent, Type, Changed, and Content. Inside of Content I am storing NSDictionarys. NSFetchedResultsController allows me to sort by any of the keys defined in my NSManagedObjectModel but what would really be useful to me is the ability to sort by the NSDictionary's keys. Is there any way that I can do this?

You want to sort with multiple keys? GUID, Parent, Type, Changed, and Content are entities or attributes from your entity ?

I suppose you have implemented your fetchedResultsController methods and GUID, Parent, Type, Changed, and Content are the attributes of your model.

- (NSFetchedResultsController *)fetchedResultsController {
   ...
   ...
   ...
   NSSortDescriptor *sort = [[NSSortDescriptor alloc] 
                          initWithKey:@"Parent" ascending:YES];
   NSSortDescriptor *sort2 = [[NSSortDescriptor alloc] 
                          initWithKey:@"Type" ascending:YES];
   [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sort,sort2,nil]];
   ...
   ...
return _fetchedResultsController;    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM