views:

55

answers:

2

I'm developing an iPhone app which downloads data from the internet and creates objects from that data. It is possible to create the same type of object on the device. The objects from the web should not be saved in the Core Data database, but the objects created on the device should.

When I save i use this standard call:

     NSError *error;
 if (![context save:&error])
  NSLog(@"Error %@", [error localizedDescription]);

Does anyone know how to do this?

A: 

I'll preface this by saying I haven't been working with core data that long, so take this with a grain of salt...

...do you need to work with multiple web routes at the same time? If it is just one at a time, maybe save it in core data as "last downloaded route". When you download a new one, load that "last downloaded" object and overwrite it's data with the new route. That way you are only keeping the most recent one.

If you are set on not saving ANY of the web routes, I wouldn't even involve them in your core data context. Just download them and work with the data directly in the app - I might be confused as to how your app works here, but if you don't want to save the web routes in the store, why are you adding them to the context?

The only other thing I can think of is either to have separate contexts - otherwise, you would have to then go back and delete the web downloaded objects after saving, which would be a mess.

If you provide more specifics on the data model and how you are using the data, maybe I could give more specific advice.

Jim
+1  A: 

I would create an in-memory persistent store and assign the "transient" web downloaded instances to this store. Instances that you want to save should be assigned to an on-disk persistent store.

Barry Wark