Search code examples
objective-cipadcore-datauisplitviewcontroller

CoreData iPad application crash


I have made a new split view iPad app using CoreData. All I have done is added a new attribute to the entity which is a string. (The default being timeStamp, date).

This causes the app to crash upon startup just adding it. Why is this so?

I was for example going to play around with it to display text rather than its default date. E.g. changing this line: [newManagedObject setValue:[NSDate date] forKey:@"timeStamp"]; Using a different value other than a date.


Solution

  • It's almost certainly because you already had the app installed on the device, and now that you have changed the Core Data model the existing database has the wrong structure. You can confirm this by looking in the XCode console window after the crash: you should see an exception stack trace and, above that, a message along the lines of "The model used to open the store is incompatible with the one used to create the store." When XCode installs your modified version of the app onto the device, it doesn't overwrite the existing database automatically, which is a pain and regularly catches me out ;-)

    You have to uninstall the app from the device after making any changes to the Core Data model, so that it starts with a clean version of the database. There's more info about this aspect of Core Data at Shannon Appelcline's iPhone in Action site.