开发者

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

开发者 https://www.devze.com 2023-01-14 07:52 出处:网络
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 a

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 coreda开发者_开发技巧ta 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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消