Question

I am updating my Core Data model to include more entities and attributes and need some guidance when it comes to relationships and NSManagedObjectSubclasses.

I have followed the guidance here http://www.raywenderlich.com/27657/how-to-perform-a-lightweight-core-data-migration and successfully managed to add a new model version of my app, add in a new entity with an attribute and set up the relationship to another entity. I have also managed to successfully update the AppDelegate settings.

That's working very well. However, I need to generate an NSManagedObject Subclass for my new entity as well as update the relationship with another entity with it's NSManagedObjectSubclass.

I have tested my app and it's still working with the data in tact, but if I generate a new NSmanagedObject subclass for the new entity and regenerate the NSManagedOBject subclass for the other entity that has a relationship to this new entity, won't that require me to delete the app from the phone with the model mismatch?

I have not tried it because I need to test this out before making changes, but I needed some guidance on this issue.

Was it helpful?

Solution

Migrations only affect the persistent store, making sure that it matches your managed object model.

Your NSManagedObject subclasses use the model and persistent store, but they don't influence it.

So yes, you can safely continue with your next step: making sure that your NSManagedObject subclasses (and other parts of your application) are updated to handle the structure of your newly-updated managed object model.

But just to make it absolutely clear: if you change the model again (tweaking relations etc) then your test device's database may become incompatible and you may need to start over with your migration tests.

This is why I asked if you use source control. You will almost certainly want to build and install previous versions of your app so you can repeatedly test migrations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top