TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

CoreDataProject - Writing duplicate records

Forums > 100 Days of SwiftUI

Just completed the section on Dynamic Filtering, which works fine. The 'Add' button keeps adding the same records. Mistakenly, I was under the impression that the SceneDelegate code:

let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy

avoids writing duplicate data. Obvioulsy, it only merges what is in the cache, before saving. Anyone have some ready made code that validates additions against the DB first? Regards.

3      

I tried to find the lesson in 100 Days of SwiftUI and wasn't able to find it. Could you please give me a link or the code snippet which adds the object? Because I doubt it's the same object but it's everytime a new instance of the object with the same property values.

Have you seen these articles here: https://www.hackingwithswift.com/books/ios-swiftui/ensuring-core-data-objects-are-unique-using-constraints https://www.hackingwithswift.com/read/38/6/how-to-make-a-core-data-attribute-unique-using-constraints

3      

Thank you Hatsushira.

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.