store multiple items in one core data record
func insertItems(coreDataTable : String, records: NSArray) -> Bool {
let error: NSError?
for(item in records as NSDictionary!) {
let entity = NSEntityDescription.entityForName(coreDataTable, inManagedObjectContext: self.managedContext)
var record = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedContext) as Record!
record.name = item["name"]
if (!self.mainObjectContext.save()) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
//abort();
return false
}
}
return true
}