添加新实体(核心数据)时出现 Swift 错误

标签 swift core-data

我刚刚使用 Core Data 创建了一个新的 xcode 项目(Master-datail 应用程序)。 在我创建了一个新实体(没有代码添加到 Controller 中)之后,我试图在 iOS 模拟器上打开应用程序,但我收到了这个错误

2015-03-27 17:59:20.882 Blog Reader[2677:301117] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/stevik/Library/Developer/CoreSimulator/Devices/29A6C356-8AFA-48BA-B0C0-B6031D760ECE/data/Containers/Data/Application/88603D30-BAED-4F1A-95AB-ADD87C3A469B/Documents/Blog_Reader.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x78f4edd0 {metadata={ NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { Event = <5431c046 d30e7f32 c2cc8099 58add1e7 579ad104 a3aa8fc4 846e97d7 af01cc79>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "25DE15EE-E903-4544-888B-7326455CF4B3"; "_NSAutoVacuumLevel" = 2; }, reason=The model used to open the store is incompatible with the one used to create the store} with userInfo dictionary { metadata = { NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { Event = <5431c046 d30e7f32 c2cc8099 58add1e7 579ad104 a3aa8fc4 846e97d7 af01cc79>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "25DE15EE-E903-4544-888B-7326455CF4B3"; "_NSAutoVacuumLevel" = 2; }; reason = "The model used to open the store is incompatible with the one used to create the store"; } 2015-03-27 17:59:20.885 Blog Reader[2677:301117] Unresolved error Optional(Error Domain=YOUR_ERROR_DOMAIN Code=9999 "Failed to initialize the application's saved data" UserInfo=0x78ea27b0 {NSLocalizedDescription=Failed to initialize the application's saved data, NSUnderlyingError=0x78f4edf0 "The operation couldn’t be completed. (Cocoa error 134100.)", NSLocalizedFailureReason=There was an error creating or loading the application's saved data.}), Optional([NSLocalizedDescription: Failed to initialize the application's saved data, NSUnderlyingError: Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x78f4edd0 {metadata={ NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { Event = <5431c046 d30e7f32 c2cc8099 58add1e7 579ad104 a3aa8fc4 846e97d7 af01cc79>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "25DE15EE-E903-4544-888B-7326455CF4B3"; "_NSAutoVacuumLevel" = 2; }, reason=The model used to open the store is incompatible with the one used to create the store}, NSLocalizedFailureReason: There was an error creating or loading the application's saved data.])

最佳答案

除非您实现模型迁移,否则您无法更改核心数据模型并继续使用相同的持久存储文件。苹果提供considerable documentation on this .然而,在应用程序开发期间,您通常可以从设备/模拟器中删除应用程序并安装一个新副本。这会删除任何现有数据,但在处理模型时通常没问题。

关于添加新实体(核心数据)时出现 Swift 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29306434/

相关文章:

ios - 在 Xcode 8.1 中创建 NSManagedObject 类显示错误

ios - iOS 有输入和存储街道地址的标准方法吗?

ios - 无法将类型 'UIView' (0x1102beb40) 的值转换为 'SKView' (0x10f0814c8)

ios - Cocoapods 安装,然后是 "linker command failed with exit code 1 "

ios - 通过游戏中心应用程序进入游戏时如何接收基于回合的匹配数据?

iphone - CoreData 应用程序在执行获取请求时卡住 pthread_mutex_lock

ios - 如何在 iOS 中设置状态栏以显示消息?

ios - 如何使用 swift 在 Storyboard模式下重用 UITabBarController 中的 View Controller

ios - NSManagedObjectContext -保存: causing SIGSEGV crash

objective-c - 核心数据实体中 bool 属性的类型是什么?