In my entity i have 5 attributes and some values are already saved, i cannot search specific value from saved data and update the data and save it.
Data 1
name = Conc;
url = "http://192.168.1.12/snapshot";
ipaddress = "http://192.168.1.102";
pass = we;
prof = "Profile_1";
user = web;
Data 2
name = P1;
url = "http://192.168.1.150/hello";
ipaddress = "http://192.168.1.112";
pass = hello;
prof = "Profile_1";
user = web;
All this is saved in my core data i wanted to search the name P1 and replace the data which user adds into the text field and update it.
but it adds as a new entry into the core data.
code used to save the data:
var coreDataIpAddress: [NSManagedObject] = []
guard let appDelegate =
UIApplication.shared.delegate as? AppDelegate else {
return
}
// 1
let managedContext =
appDelegate.persistentContainer.viewContext
// 2
let entity =
NSEntityDescription.entity(forEntityName: "Data",
in: managedContext)!
let Data = NSManagedObject(entity: entity,
insertInto: managedContext)
// 3
cameraData.setValue(ipAddress, forKey: "ipaddress")
cameraData.setValue(snapshotUrl, forKey: "url")
cameraData.setValue(cameraName, forKey: "name")
cameraData.setValue(userName, forKey: "user")
cameraData.setValue(password, forKey: "pass")
cameraData.setValue(profileToken, forKey: "prof")
// 4
do {
try managedContext.save()
saveCameraDetails.append(Data)
} catch let error as NSError {
print("Could not save. \(error), \(error.userInfo)")
}
}