I\'m not sure what I\'m doing wrong here, but when I save the first time into coredata, it works just fine. When I try to overwrite that, it doesn\'t.
func t
//For Swift UI inside the view outside the body :)
@Environment(.managedObjectContext) var managedObjectContext
var isNewRecord = false
let aNewContact: Contact!
let fetchConcact: NSFetchRequest = Contact.fetchRequest() as! NSFetchRequest
fetchConcact.predicate = NSPredicate(format: "record_id == %@", contactRemoteModel.contacts[i].record_id as CVarArg)
let results = try? managedObjectContext.fetch(fetchConcact)
if results?.count == 0 {
// here you are inserting
aNewContact = Contact(context: managedObjectContext)
aNewContact.id = UUID()
isNewRecord = true
print("Insert")
} else {
// here you are updating
aNewContact = results?.first
print("UpDate")
}