A to-many relationship is represented as an NSSet
when using valueForKey:
.
To turn that into a sorted NSArray
, you can use the sortedArrayUsingDescriptors:
method:
NSSet *allFields = [table valueForKey:@"fields"];
NSSortDescriptor *indexSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"index" ascending:YES];
NSArray *sortedFields = [allFields sortedArrayUsingDescriptors:@[indexSortDescriptor]];