store multiple items in one core data record code example
Example: 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()) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
return false
}
}
return true
}