ios_catalogue1-3 Exercise 3: Testing the .deny Delete Rule =========================================================== A temporary test (in the preview, with the shared sample data, where "Dune" is a Book): Button("Delete Book type") { let repo = CatalogueRepository(context: context) if let book = try? repo.itemTypes().first(where: { $0.name == "Book" }) { context.delete(book) do { try context.save(); print("saved: type deleted") } catch { print("save failed: \(error)") } } } What to record: whether context.delete(book) itself throws or traps (it is not a throwing call, so it should not); whether save() throws; what the error says; and whether "Book" is still in the Item types list afterwards. What the rule is MEANT to do: with deleteRule: .deny, deleting an object that still has related objects is refused, normally reported as an error when the changes are saved. If you see that, the repository can catch it and turn it into a friendly message. If you see something else (the type is deleted and Dune is left with no type, or a crash), then .deny is not behaving as the sources I used implied, and the repository must enforce the rule itself: func deleteType(_ type: ItemType) throws { guard type.items.isEmpty else { throw CatalogueError.typeInUse(type.name) } context.delete(type) try context.save() } In fact, since the four types are fixed and the app never offers to delete one, the BEST design is to have no deleteType function at all: the rule cannot be broken by code that does not exist. Keeping .deny as a second line of defence is still sensible if you confirm it works; if you cannot confirm it, rely on the first line. Whatever you find, write it in your own notes with the Xcode and iOS versions: this is the sort of behaviour that changes between releases.