Domanda

I need to find a way to perserve the sort order given by the server, when using a fetchedresultscontroller, even though the parameter used to sort by in the server is not returned with the data.

Each set of objects can be sorted in various ways, that is returned as json in an array with the correct sort order

I have them in different ordered sets contained by entities that also contain meta data, and sort by a parameter that is the same in all items, but the order in my ordered set is not used to sort by anyway.

The target iOS version is 6.1-7.0

My fetch request predicate is:

fetchRequest.predicate = [NSPredicate predicateWithFormat:@"SELF in %@.items", itemList]; where items is an @property (nonatomic, retain) NSOrderedSet *items; so the predicate clearly refers to the ordered set.

Any better predicates and sort descriptors for working with ordered sets?

Any better ways to structure my model?

Thank you!

È stato utile?

Soluzione

I have decided to abandon using ordered sets. They are not very flexible and you will run into issues like the one you have all the time. (One problem is that they are neither derived from NSArray nor NSSet so some standard manipulations become very difficult.)

I suggest to introduce a position attribute to your entity or entities that need to be in a particular order. You can store this the moment the data comes in. The rest is trivial.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top