views:

41

answers:

1

Hello,

My iphone app retrieve data from a RestServer in the following format:

{
data => (
    {
             date => "20100710T12:21:23+02:00",
             value => 0.1
            },
    {
             date => "20100710T12:30:23+02:00",
             value => 25
            },
             ...
    {
             date => "20100710T15:21:23+02:00",
             value => 3
            }
       ),
 field1 => value1,
 field2 => value2
}

Today, I loop though the array (objectAtIndex:0) and save in Core Date each object like:

        {
             date => "20100710T15:21:23+02:00",
             value => 3
            }

I have created an Entity in core data (Measure) with 2 properties (date, value). Is there a mean to save directly the array without having to save the elements one after the other ?

well, I have forgotten an important point in fact. On top of this I would need the data to be inserted only if there is not already a value for this date. The date is knid of the primary key in this case. According to what I read I do not think this is a possible feature out of the box for core data. In that case, is there a quickest way to do this rather than checking the record existence one by one before inserting it in the DB ?

Thanks a lot, Luc

+3  A: 

Each element in the array is represented by a single object in Core Data so, yes, you have to create an object for each element. If you didn't have to do this then you wouldn't have an object graph in the first place.

You do have to check for an existing object because every object in the Core Data stack is utterly unique. However, doing so is no more complicated than checking for the same data in an array or a SQL table.

Core Data's strength is the management of data models with complex relationships between data entities. That is often overkill for data that is little more than a single, dumb table with no relationships. However, the ease of integration with the UI and other parts of the app/system usually pays for the up front overkill in inputting that single table.

TechZen
Thanks a lot for this. At the end I should end up with several entities with relationships though.
Luc