Jasarien
Jasarien

Reputation: 58448

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?

Upvotes: 7

Views: 1731

Answers (1)

Louis Gerbarg
Louis Gerbarg

Reputation: 43452

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
}

Upvotes: 18

Related Questions