0

If I were to use a predicate with the IN operator for fetching results using Core Data:

NSPredicate *inPredicate = [NSPredicate predicateWithFormat: @"attribute IN %@", aCollection];

and that attribute has unique values, is it right to assume the order in which the results are returned corresponds with the order of the values in the collection, or would I need to sort them afterwards?

4

1 回答 1

0

You'll need to sort them with an NSSortDescriptor.

If you want to sort by the order of your IN collection, follow the pattern described in Core Data (SQLite backed) custom sorting of strings, but add an Integer property instead of a Boolean, and make the Integer values correspond to the index of your collection. Then create an NSSortDescriptor to sort by this custom property.

If more complex sorting is needed, you can put CoreData aside and sort the fetchedObjects array using [NSArray sortedArrayUsingComparator:].

于 2012-09-10T17:53:05.790 回答