Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain JSON array order with Restkit managed objects

So i've got some JSON data and I want to maintain the order in which that data is received with restkit and managed objects and I havent been able to find the best way of doing this. When the order changes I need to make sure duplicates are not created and they are saved properly with core data.

I believe an extra field in the datamodel for this specific entity is needed, lets call it order, and assume is assigned when creating the RKEntityMapping. I'm just not sure how to get the array index using restkit.

Any help appreciated, thanks.

like image 304
glued Avatar asked Jun 13 '13 02:06

glued


1 Answers

The index of each object in the response array is provided to the mapping via metadata. Add something like this to your mapping:

@"@metadata.mapping.collectionIndex" :  @"order"

There is a bit more information on metadata in the 'Metadata Mapping' section of the RKMappingOperation docs

like image 72
Wain Avatar answered Sep 21 '22 18:09

Wain