iosobjective-ccore-datanspersistentstore

Core Data - detect if the database store was already created or not


I'm using Core Data and I need to detect if the database store was already created or not.

I tried using metadataForPersistentStoreOfType:URL:error: and check if its returning a valid metadata, but apparently this method returns nil if no metadata exists but also an error.
So I can't really tell if its because the store wasn't created yet, or if an error accord

Problem is, I already has a version on the app store, so I can't for example set a flag (like "store_created") on user default in the current version...

So I need a way to detect when user installing this current version, if the store was already created (meaning he already installed the previous version), or not


Solution

  • [[NSFileManager defaultManager] fileExistsAtPath:stringThatHoldsPathToMyPersistentStore]