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.
+1
A:
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
Amorya
2010-08-30 16:49:26
forgive my ignorance here, let me see if I understand the concept .... the model will be independent of the new app bundle so comparing the metadata will show me if the version number loaded from the metadata is older than the current app. If it is I can go and iterate through my new plist and insert new objects into the model as required. If this is correct then yes, this is exactly what I need. I don't need to migrate the model you see ... just populate it with new items from the plist when a new version of the app is launched for the first time.
Lee Probert
2010-09-01 07:54:48
A:
If you want the app version, just check the Bundle version
key in the info.plist file.
TechZen
2010-08-30 17:11:58
if I am correct in the assumption that Amorya's suggested technique (above) is what I need then I will indeed be inserting the app version id into the metadata of the persistent store. Thanks.
Lee Probert
2010-09-01 07:56:43
Amorya's suggestion will tell you information about the model file itself but it won't tell you about the app version. Unless you change you the model with every version, the two version won't necessarily line up. If your goal is to trigger an update when the app version changes, you need to track the app version directly.
TechZen
2010-09-01 14:01:53
I believe the suggestion is to use the NSPersistentStore's metadata to store a reference to the app version number so I can cross reference it. Either way, both answers will help me achieve what I need. Thanks.
Lee Probert
2010-09-05 14:04:54