I started programming with Swift and my project needs to DB. I use Core Data and have a lot of problem with this.
One of the most important issue is "insert into DB", After insert i fetch data and It returned a list of data that only last object is OK, all the last objects are Here is my insert, fetch and log of fetched data:
Insert
let newItem = NSEntityDescription.insertNewObjectForEntityForName("DeviceList", inManagedObjectContext:managedContext) as! DeviceList
newItem.mac = deviceObject.mac
newItem.name = deviceObject.name
//4
var error: NSError?
if !managedContext.save(&error) {
println("Could not save \(error), \(error?.userInfo)")
return false
}
Fetch
let fetchRequest = NSFetchRequest(entityName: "DeviceList")
if let fetchResults = managedObjectContext!.executeFetchRequest(fetchRequest, error: nil) as? [String] {
result = fetchResults
}
print("result:\(result)")
Log
"<MyAPP.DeviceList: 0x7be58fe0> (entity: DeviceList; id: 0x7be6f480 <x-coredata://72931FFE-1CAC-4A5C-BD32-817681C2439E/DeviceList/p1> ; data: <fault>)",
"<MyAPP.DeviceList: 0x7be600f0> (entity: DeviceList; id: 0x7be59010 <x-coredata://72931FFE-1CAC-4A5C-BD32-817681C2439E/DeviceList/p2> ; data: <fault>)",
"<MyAPP.DeviceList: 0x7bea5e30> (entity: DeviceList; id: 0x7be60120 <x-coredata://72931FFE-1CAC-4A5C-BD32-817681C2439E/DeviceList/p3> ; data: <fault>)",
"<MyAPP.DeviceList: 0x7be6e0e0> (entity: DeviceList; id: 0x7bea5e60 <x-coredata://72931FFE-1CAC-4A5C-BD32-817681C2439E/DeviceList/p4> ; data: <fault>)",
"<MyAPP.DeviceList: 0x7beaaa00> (entity: DeviceList; id: 0x7beac3c0 <x-coredata://72931FFE-1CAC-4A5C-BD32-817681C2439E/DeviceList/p5> ; data: <fault>)",
"<MyAPP.DeviceList: 0x7beaaae0> (entity: DeviceList; id: 0x7be6e150 <x-coredata://72931FFE-1CAC-4A5C-BD32-817681C2439E/DeviceList/p6> ; data: <fault>)",
"<MyAPP.DeviceList: 0x7beaac00> (entity: DeviceList; id: 0x7beaab50 <x-coredata://72931FFE-1CAC-4A5C-BD32-817681C2439E/DeviceList/p7> ; data: <fault>)",
"<MyAPP.DeviceList: 0x7bea3600> (entity: DeviceList; id: 0x7beaac30 <x-coredata://72931FFE-1CAC-4A5C-BD32-817681C2439E/DeviceList/p8> ; data: <fault>)",
"<MyAPP.DeviceList: 0x7c03f5f0> (entity: DeviceList; id: 0x7c03c2a0 <x-coredata://72931FFE-1CAC-4A5C-BD32-817681C2439E/DeviceList/p9> ; data: {\n mac = \"00:00:00:13:43:59\";\n name = Atim;\n})"
Is it any problem in my insert function?
And I also opened sqlite database that stored in simulator by SQLiteManager (FireFox ad-one) and it does not show any record in DB, Why? When I was programing with Objective-C, The sqlite file shows all data without any problem!
Aucun commentaire:
Enregistrer un commentaire