CoreData iPad 应用程序崩溃
我使用 CoreData 制作了一个新的分割视图 iPad 应用程序。我所做的只是向实体添加一个新属性,它是一个字符串。 (默认为时间戳、日期)。
这会导致应用程序在启动时仅添加它就会崩溃。为什么会这样呢?
例如,我打算用它来显示文本而不是默认日期。例如更改这一行: [newManagedObject setValue:[NSDate date] forKey:@"timeStamp"];使用日期以外的不同值。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几乎可以肯定,因为您已经在设备上安装了应用程序,现在您已经更改了核心数据模型,现有数据库的结构错误。您可以通过在崩溃后查看 XCode 控制台窗口来确认这一点:您应该看到异常堆栈跟踪,并且在其上方显示一条消息,内容为“用于打开商店的模型与用于创建商店的模型不兼容”。店铺。”当 XCode 将应用程序的修改版本安装到设备上时,它不会自动覆盖现有数据库,这很痛苦并且经常让我感到困惑;-)
在对数据库进行任何更改后,您必须从设备上卸载应用程序核心数据模型,以便它以干净版本的数据库开始。有 有关核心数据这方面的更多信息,请访问 Shannon Appelcline 的 iPhone in Action 网站。
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.