我正在尝试使用json
保存来自Core Data
文件的新对象。在此对象中,timestamp
格式为string
。首先,我将其转换为NSDate
,然后将其设置为对象的timeStamp
属性。
我在核心数据模型中有Posts
个实体,并且有以下属性:
属性类型
我收到以下错误:
错误域= NSCocoaErrorDomain代码= 134100"无法完成操作。 (可可错误134100。)" UserInfo = 0x7f86cac69580 {metadata = { NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { 帖子=< 2c8eee3f 71ece20d 3b7daa20 e8e835ec 89126883 0b53dbd6 62992f34 dc3fb804&gt ;; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers =( "" ); NSStoreType = SQLite; NSStoreUUID =" CF57FEED-4E12-463F-8E5C-11F004518AE9&#34 ;; " _NSAutoVacuumLevel" = 2; },reason =用于打开商店的模型与用于创建商店的模型不兼容,带有userInfo字典{ metadata = { NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { 帖子=< 2c8eee3f 71ece20d 3b7daa20 e8e835ec 89126883 0b53dbd6 62992f34 dc3fb804&gt ;; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers =( "" ); NSStoreType = SQLite; NSStoreUUID =" CF57FEED-4E12-463F-8E5C-11F004518AE9&#34 ;; " _NSAutoVacuumLevel" = 2; }; reason ="用于打开商店的模型与用于创建商店的模型不兼容&#34 ;; }
这是我的代码:
for item in items {
if let title = item["title"] as? String {
if let content = item["content"] as? String {
if let timeStamp = item["published"]! as? String {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss Z"
let date: NSDate? = dateFormatter.dateFromString(timeStamp)!
println(date!)
var newPost = NSEntityDescription.insertNewObjectForEntityForName("Posts", inManagedObjectContext: context) as! NSManagedObject
newPost.setValue(title, forKey: "title")
newPost.setValue(content, forKey: "content")
newPost.setValue(date!, forKey: "timeStamp")
context.save(nil)
}
}
}
}
}
答案 0 :(得分:0)
试试这个 转到模拟器并按重置内容和设置。当您在核心数据中出现某些属性时,通常会发生此错误。