Lee Probert
Lee Probert

Reputation: 10859

CoreData how to detect new version of an app so I can update the model?

I have a very simple model that is created when the app is launched for the very first time and populated with the contents of a plist. I will need to re-create the model again when an update to the app is downloaded and launched. I know that you can version coredata models but I don't foresee the model itself is going to change. I will just need to go through the existing array of objects and add new objects from the plist. For this I need to check the version number of the app and somehow detect it is different from the model on the device.

Upvotes: 1

Views: 773

Answers (2)

TechZen
TechZen

Reputation: 64428

If you want the app version, just check the Bundle version key in the info.plist file.

Upvotes: 0

Amy Worrall
Amy Worrall

Reputation: 16337

Take a look at this method on NSPersistentStore

+ (BOOL)setMetadata:(NSDictionary *)metadata forPersistentStoreWithURL:(NSURL *)url error:(NSError **)error

You can set an arbitrary dictionary of key/value pairs. Make one to represent your version. Then you can load back that dictionary with:

+ (NSDictionary *)metadataForPersistentStoreWithURL:(NSURL *)url error:(NSError **)error

Upvotes: 3

Related Questions