Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a Persistent Store a requirement for Core Data on the iPhone?

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?

like image 578
Jasarien Avatar asked Jul 23 '09 15:07

Jasarien


1 Answers

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
}
like image 187
Louis Gerbarg Avatar answered Oct 21 '22 17:10

Louis Gerbarg