0

when dealing with CoreData, I've run into a few problems I'm trying to nip in the bud for future proofing the system out of the gate. The simple fact of the matter is that I've never done anything like this before (work with CoreData that is). While I've managed to figure out how to work with it in the app, I need to know a decent practice to signal an app between versions that default data needs to be refresh on first app launch.

So right now, in my AppDelegate, I setup my managed object context, and I perform a fetch request to see if there are any records at all in a particular table/entity. I only want this to happen on first launch so im not constantly rewriting the contents of the DB every app launch. Anyways, so it goes ahead and uses Object Models to handle inserting of data amongst the entities in question (theres a few)

Now, for this version of the app, it's going into the store without an API (thats a far future thing), but between versions released to the app store, we may have to update specific information within the entities (for example: prices), again I only want this refresh to happen on app launch. Also, the schema MIGHT change, Im not sure if or when, but I'd like to make sure this can accomodate that just in case.

I figured, versioning the coredata "Add Model Version" would do the trick, set the new db version as the active version, but when I launch the app in the simulator, nothing happens which tells me that the data inside is being retained.

Any help towards what it is that I should do to accomodate this would be appreciated. Thank you!

RedactedProfile
  • 2,748
  • 6
  • 32
  • 51
  • I can't figure out what you are asking. It it simply, "How do I tell the first time a particular version of my app is launched"? – memmons Feb 04 '13 at 18:30
  • I've already got that. What Im asking is for an approach about how to force perform a refresh of default provided data into the entities **after** launching for the first time **after** an update from the app store in the future, all things considering with a schema update and updates of the default data. – RedactedProfile Feb 04 '13 at 18:33
  • So, you have a set of default data which may change between versions. In those cases you want to remove/reinsert and/or update the default data the first time the new version is launched. Correct? – memmons Feb 04 '13 at 19:52

1 Answers1

1

You should find the Core Data Model Versioning and Data Migration guide useful:

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/Introduction.html

You'll also probably find Method for import initial data with coredata useful.

Community
  • 1
  • 1
CSmith
  • 13,318
  • 3
  • 39
  • 42