ios_catalogue1-3 Exercise 2: Proving No Duplicate Tags ======================================================= A temporary button in ContentView: @Environment(\.modelContext) private var context ... Button("Test tags") { let repo = CatalogueRepository(context: context) _ = try? repo.tag(named: "Sci-Fi") _ = try? repo.tag(named: "SCI-FI") _ = try? repo.tag(named: " sci-fi ") try? context.save() } Prediction: ONE tag, named "Sci-Fi". - 1st call: no tag with key "sci-fi": a new Tag("Sci-Fi") is created and inserted. - 2nd call: key("SCI-FI") == "sci-fi": found, returned untouched. - 3rd call: cleaned to "sci-fi", key "sci-fi": found again. The name stays as first typed, "Sci-Fi". (In the canvas preview "sci-fi" already exists from the sample data, so the stored name there is "sci-fi" and the button adds nothing: the count stays three.) If the function simply did context.insert(Tag(name: name)): The unique constraint is on key. Per a third-party note on the WWDC23 session, inserting a model with an existing unique value UPDATES the existing record instead of failing. So you would probably still end up with one tag, but its name would be overwritten by the latest spelling ("sci-fi"), and any code holding the old object might see it change underneath it. Another possibility on some versions is an error at save time. Either way the behaviour is something you would be relying on without having verified it. Looking first removes the question: you get a defined result on every OS version. If your Xcode behaves differently from this description, that is useful information: note which behaviour you saw.