views:

406

answers:

2

Hey guys,

I'm looking to use Core Data within my iPhone app.

The app doesn't really need to store the data that is used, but it needs to be managed and queryable.

Can Core Data be used for datasets that exist purely in memory and are not persisted to the disk?

+8  A: 

Absolutely, just set the store type to NSInMemoryStoreType. More specifically, you set it up like this:

NSError *error = nil;

//Ignore that it is called an "NSPersistentStore", it is not persisted
NSPersistentStore *inMemoryStore = [persistentStoreCoorindator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:&error];

if (inMemoryStore && !error) {
  //It is setup
}
Louis Gerbarg
Perfect! Thanks!
Jasarien
A: 

It is NOT persistent? With an inablilty to save due to validation checks failing, I'm seeing more errors each time I run the app (on the simulator - different?). I'm assuming this means persistence happens and I'm compounding the problem on each run. Comment?