Reputation: 32
I'd like to sava data (text) if return is clicked on the keyboard. But it's not working. I'd like to display the text, which was saved in a table view cell and it should be also available after the next start of the app.
My code:
func textFieldShouldReturn(textField: UITextField) -> Bool {
tableViewData.append(textField.text)
textField.text = ""
self.tableView.reloadData()
textField.resignFirstResponder()
// Reference to our app delegate
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
// Reference moc
let contxt: NSManagedObjectContext = appDel.managedObjectContext!
let en = NSEntityDescription.entityForName("note", inManagedObjectContext: contxt)
// Create instance of pur data model an initialize
var newNote = Model(entity: en!, insertIntoManagedObjectContext: contxt)
// Map our properties
newNote.note = textField.text
// Save our context
contxt.save(nil)
println(newNote)
return true
}
Log:
CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/Patti/Library/Developer/CoreSimulator/Devices/A70306D7-76BE-489A-82B3-FBAA9390D5A4/data/Containers/Data/Application/FC51C1B7-416B-463E-B976-C175642A4B34/Documents/Note_App.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x7fa79add8080 {metadata={
NSPersistenceFrameworkVersion = 519;
NSStoreModelVersionHashes = {
Notes = <674765e4 00e077d5 e3b4d2ca 2795eee2 42850989 4a2a825a 0c289097 387aa3a5>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "8348BBED-7C75-4EF5-B73C-075E8719696E";
"_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 = {
Notes = <674765e4 00e077d5 e3b4d2ca 2795eee2 42850989 4a2a825a 0c289097 387aa3a5>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "8348BBED-7C75-4EF5-B73C-075E8719696E";
"_NSAutoVacuumLevel" = 2;
};
reason = "The model used to open the store is incompatible with the one used to create the store";
}
2014-10-19 12:05:19.559 Note App[2450:43299] Unresolved error Optional(Error Domain=YOUR_ERROR_DOMAIN Code=9999 "Failed to initialize the application's saved data" UserInfo=0x7fa79addb450 {NSLocalizedFailureReason=There was an error creating or loading the application's saved data., NSLocalizedDescription=Failed to initialize the application's saved data, NSUnderlyingError=0x7fa79add80c0 "The operation couldn’t be completed. (Cocoa error 134100.)"}), Optional([NSLocalizedFailureReason: There was an error creating or loading the application's saved data., 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=0x7fa79add8080 {metadata={
NSPersistenceFrameworkVersion = 519;
NSStoreModelVersionHashes = {
Notes = <674765e4 00e077d5 e3b4d2ca 2795eee2 42850989 4a2a825a 0c289097 387aa3a5>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "8348BBED-7C75-4EF5-B73C-075E8719696E";
"_NSAutoVacuumLevel" = 2;
}, reason=The model used to open the store is incompatible with the one used to create the store}])
Upvotes: 0
Views: 1702
Reputation: 150715
The last line of your crash log tells you what has gone wrong.
You've changed your model since running the app. You either need to enable auto migration so that such changes are corrected automatically, or just delete the app from the simulator and run it again.
Upvotes: 3