ios_catalogue1-7 Exercise 3: Tags No Item Uses =============================================== Keep: + Zero risk of deleting something by accident. + It remains a suggestion, so spellings stay consistent over time. + No extra code. - The store slowly collects dead tags; a tag-filter row must hide them (Chapter 8). Delete (when the last item loses it): + The tag list always reflects reality. + Simple to explain to the user. - Needs code on EVERY path that removes a link: edit, item delete, import. - A typo tag deleted and retyped costs nothing, but a deliberate tag the user is about to reuse disappears. A reasonable choice: keep them, but exclude unused tags from the filter row, and add a cleanup that removes orphans on request or at launch. Code for the cleanup (in CatalogueRepository, after any save or delete that changes tags): func deleteUnusedTags() throws { let tags = try context.fetch(FetchDescriptor()) for tag in tags where tag.items.isEmpty { context.delete(tag) } try context.save() } It must check tag.items.isEmpty AFTER the item changes are applied (inside or after the same save), and it must not run while a form still holds those tag names in a draft that has not yet been saved, or Save would recreate them. Call it after delete(_:) and after save(_:tagNames:), never from the form. Test it with an item that is the only user of a tag: delete the item and confirm the tag is gone.