Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

whitedragon101

macrumors 65816
Original poster
Sep 11, 2008
1,349
339
When using core data I sometimes think oh I need a new entity or attribute. When I add these I click the "create new NSManagedObjectSubclass" button to get access to these new entities or fields. However, when I fire up the simulator it doesn't work as it says it was created using a different data model. So I delete the app start again but all the data is gone.

Is there a way to avoid this?

This is going to be crucial for updating the app for future versions because it won't be good for the user to loose all their recorded information every time I need to add an entity or attribute.
 
When using core data I sometimes think oh I need a new entity or attribute. When I add these I click the "create new NSManagedObjectSubclass" button to get access to these new entities or fields. However, when I fire up the simulator it doesn't work as it says it was created using a different data model. So I delete the app start again but all the data is gone.

Is there a way to avoid this?

This is going to be crucial for updating the app for future versions because it won't be good for the user to loose all their recorded information every time I need to add an entity or attribute.

I think you'll need to make a new version of the model and then develop a migration policy (so that you can handle the changes between model versions, such as the entities/attributes you've added/removed/modified). As far as I know that's the preferred way of dealing with changes in the model.

More information from Apple.
 
^ as above bonus being if your only adding new entities or adding new attributes to you existing entities then you can take advantage of Auto migration. Auto migration will take care of a lot of model change these days.

Still as above at a minimum you need to make model versions for it to work.
 
Thanks guys.

I really hope they make that easier in the future maybe with all the new swift and xcode 6 stuff. I didn't realise this would be an issue. If you add a table or field to a sql db it doesn't kill your app.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.