Reputation: 523
What I want should be simple but for some reason it's not working properly. So, when I rearrange my table view each row is saved in an array friends
as a subclass of NSManagedObject in the same order as in the table view(from top to bottom). If the friends view shows two rows, friend1 and friend2, friends[0]
is friend1 and friends[1]
is friend2.
Whenever the table order has changed, I want the data to be stored in core data in the same order as in the friends
array.
Is there any simple way to replace all core data with my friends
array?
Upvotes: 0
Views: 60
Reputation: 28409
If you want to manage an order that has nothing to do with sorted attributes, you can make the relationship "ordered" which will result in the relationship being NSOrderedSet
.
You can then manipulate the ordering however you desire, and when you enumerate the collection, it will be in the order you stipulate.
Note, however, that there are some restrictions on NSOrderedSet
which are stipulated in the Core Data documentation.
Upvotes: 1
Reputation: 168
Objects in core data has no order, just like Set.
If you have an entity with to-many relationship with friends, then you can use NSOrderedSet to keep order.
Or, you can set up a property to keep order index as a sort condition when you fetch objects from core data.
Upvotes: 0
Reputation: 285092
The default collection type in Core Data is NSSet
which is an unordered type.
NSSortDescriptor
when fetching the dataUpvotes: 2