It's the first time i'm implementing the Core Data framework.
The logic i'm following is the following - i've created the Data Model (called Db with three Attributes - "Line", "Opt1", "Opt2" all are strings).
Then i've implemented the following code inside a function that runs on viewDidLoad
func startme(){
// i'm appending the NSManagedObject arrays
let managedContext = appDelegate.managedObjectContext!
let entity = NSEntityDescription.entityForName("Db", inManagedObjectContext: managedContext)
let opt1 = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedContext)
let opt2 = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedContext)
let question = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedContext)
opt1.setValue(myoptarray["start"]![0], forKey:"Opt1")
opt2.setValue(myoptarray["start"]![1], forKey:"Opt2")
question.setValue(linesmain["start"]!, forKey:"line")
myDataAnswersArray1.append(opt1)
myDataAnswersArray2.append(opt2)
myDataArray.append([question]) // this is an array of arrays
// implementing the required try catch
do {
try managedContext.save()
}
catch {
print("Could not save \(error)") }
// now after appending the arrays i'm inserting the data into the tableview
self.tableView1.beginUpdates()
let insertedIndexPathRange = 0..<linesmain["start"]!.count + 1
insertedIndexPaths = insertedIndexPathRange.map { NSIndexPath(forRow: $0, inSection: 0) }
self.tableView1.insertSections(NSIndexSet(index: self.myDataArray.count - 1), withRowAnimation: .Fade)
self.tableView1.insertRowsAtIndexPaths(insertedIndexPaths, withRowAnimation: .Fade)
self.tableView1.endUpdates()
}
yet after compiling the build i get those runtime errors:
2015-09-10 17:59:19.684 MyApp[18958:1295418] CoreData:
error: -addPersistentStoreWithType:SQLite configuration:(null)
URL:file:///Users/mihailseglov/Library/Developer/CoreSimulator/Devices/99956E87-379A-4BCF-953E-5EBC96527728/data/Containers/Data/Application/A97E585E-9692-4792-8C9C-144C1887784A/Documents/MyApp.sqlite
options:(null) ... returned error Error Domain=NSCocoaErrorDomain
Code=134100 "(null)" UserInfo={metadata={
NSPersistenceFrameworkVersion = 637;
NSStoreModelVersionHashes = {
Db = <7cdf7bfe 26a5b3cf 2e7f1c77 bd6cdfd1 2c51953e 77890483 b76cc39f 4c7dfb38>;
}; NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "758FA531-A288-4A60-B70B-24168CDE21B8";
"_NSAutoVacuumLevel" = 2; }, reason=The model used to open the store is
incompatible with the one used to create the store} with userInfo dictionary
I'm not sure what it means and how to overcome it. Any ideas are very welcome!