0
votes

I am trying to save a new object coming from a json file with Core Data. In this object there is a timestamp in string format. First I convert it into an NSDate then set it to the timeStamp property of the object.

I have Posts entity in core data model, and there are the following attributes:

Attribute-Type

  • content-string
  • title-string
  • timeStamp-Date

I get the following error:

Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x7f86cac69580 {metadata={ NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { Posts = <2c8eee3f 71ece20d 3b7daa20 e8e835ec 89126883 0b53dbd6 62992f34 dc3fb804>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "CF57FEED-4E12-463F-8E5C-11F004518AE9"; "_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 = { Posts = <2c8eee3f 71ece20d 3b7daa20 e8e835ec 89126883 0b53dbd6 62992f34 dc3fb804>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "CF57FEED-4E12-463F-8E5C-11F004518AE9"; "_NSAutoVacuumLevel" = 2; }; reason = "The model used to open the store is incompatible with the one used to create the store"; }

Here is my code:

    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)
                                }

                            }
                        }

                    }
                }
1
Is that the complete error message? There's almost always more than just that.Tom Harrington
@TomHarrington I updated the error code, thanks for your responseSıla Güler

1 Answers

0
votes

Try this Go to the simulator and press reset contents and settings. This error usually happens when you chance some properties in core data.