My swift code below features a func that saves a string to core data. The problem it is only saving the UserDBObj.setValue closets to the end of the code not both. So it is only saving one a time. I want RDC and aa to be saved simultaneously. In the debug area only “aa” is seen when printed. Some stated to solve this just Loop over your values and create a new instance of Users
for each value.
func openDatabse()
{
context = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "Users", in: context)
let newUser = NSManagedObject(entity: entity!, insertInto: context)
saveData(UserDBObj:newUser)
}
func saveData(UserDBObj:NSManagedObject)
{
UserDBObj.setValue("RDC", forKey: "username")
UserDBObj.setValue("aa", forKey: "username")
print("Storing Data..")
do {
try context.save()
} catch {
print("Storing data Failed")
}
fetchData()
}