Frage

I have a problem mapping json to CoreData and reading it out again. I map from json to an Activity-Entity with a relationship of last participant entities. The last_particpants is an array with the most recent participants, ordered from most recent first by the API.

{
"id": 50,
"type": "Initiative",

"last_participants": [
    {
        "id": 15,
        "first_name": "Chris",
    },
    {
        "id": 3,
        "first_name": "Mary",
    },
    {
        "id": 213,
        "first_name": "Dany",
    }
]

}

I have RestKit logging on and see that the mapping reads the array elements one by one and keeps the order. However CoreData saves them as an NSSet of entities and then the order gets lost. When I read out the data its is mixed up. What options do I have to keep the order in which the array was mapped? Any help would be great.

War es hilfreich?

Lösung

2 options:

  1. Use an ordered set in Core Data (set on the attribute in the properties inspector).
  2. Use the @metadata provided by RestKit to access the collection order during mapping.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top