开发者

CoreData iPad application crash

开发者 https://www.devze.com 2023-01-27 09:24 出处:网络
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).

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 oth开发者_开发知识库er than a date.


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.

0

精彩评论

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