I am developing an application using basic data in ios. And there are a lot of objects, and a lot of data needs to be saved, which is why I am storing the data in the return stream using the βprivate contextβ approach and using blocks. Everything is fine with all objects except one.
In this object, data is not saved the first time the application is launched and the data is synchronized, but after that, if I synchronize the data, all data in this object will be saved. Here is my code for saving data:
let programAttendeeAssignArray:NSArray? = dict["data_assign"] as AnyObject? as? NSArray for var paAssignIndex = 0; paAssignIndex < programAttendeeAssignArray?.count; paAssignIndex++ { let programAttendeeAssignObj:NSDictionary? = programAttendeeAssignArray?.objectAtIndex(paAssignIndex) as AnyObject? as? NSDictionary if let paAssignDict = programAttendeeAssignObj as? [String: AnyObject] { var keyString: String = "" if let eID = paAssignDict["id"]! as? Int { keyString = String(eID) } let paAssign: Conf_speakers = Utilities.sharedInstance.getOrCreateObjectOfEntityName("Conf_speakers", key: "id", identifier: keyString, localContext: privateContext) as! Conf_speakers if let eeid = paAssignDict["id"]! as? Int { paAssign.id = String(eeid) } if let attendee_id = paAssignDict["id1"]! as? Int { paAssign.attendee_id = String(attendee_id) } if let agenda_id = paAssignDict["id2"]! as? Int { paAssign.agenda_id = String(agenda_id) } if let updated_at = paAssignDict["id3"]! as? String { paAssign.updated_at = updated_at } } } let error: NSErrorPointer = nil do { try privateContext.save() } catch let error1 as NSError { error.memory = error1 } catch { fatalError() } dispatch_async(dispatch_get_main_queue(), { appDelegate.managedObjectContext.performBlock { () -> Void in
source share