The question here is that is it a good choice to make a linkedlist to maintain the order/priority while using coredata or should one just use a simple var to maintain the priority as a number.
While maintaining a number if a new object is inserted in an array of N objects at N/2 position then all the priority values for objects from N/2+1 -> N/2 will have to be modified which will result in that many sql queries if I am not mistaken.
If there is a linkedlist then a self relationship can be maintained to that entity say “next”. If an object is inserted at N/2 position there are just two queries which is :
1. N/2-1 -> next -> newObj
2. newObj -> next ->N/2+1
But here the problem lies in using the NSFetchedResultsController which cannot sort the fetchedresults using this relationship or can it in someway?
Please respond which one of the two techniques is better in relevance to the situations mentioned above.
The best solution would be to use a ordered to-many relationship. This uses an
NSOrderedSetwhich keeps the ordering like an array but also supports fast membership tests like a set. This only is available on iOS 5.0 or Mac OS X 10.7 or later though.If I needed to support earlier versions of iOS I’d chose the approach with an extra property for the ordering. This makes fetches much easier. A linked list structure might be easier to update, but usually fetching (for displaying the data) is done much more often, so this is the case that should be easier.
If you need to update your ordering very often you can leave big gaps between your ordering numbers.