ios_catalogue1-7 Exercise 2: Text Left in the Tag Field on Save ================================================================ Problem: the pending text lives in TagEditor's private @State `input`; the form's Save only sees draft.tagNames. Where each option stands: - ItemDraft: it is a plain struct and cannot see the field's text. Could hold it too (draft.pendingTag), but that mixes a half-typed value into the data model and every consumer of the draft must remember it. - TagEditor alone: it cannot know Save was pressed. - ItemFormView: it owns Save and the draft, so it is the natural place IF the pending text is lifted up. Recommended fix: lift the field text into the form. // ItemFormView @State private var pendingTag = "" TagEditor(tagNames: $draft.tagNames, input: $pendingTag) // TagEditor: replace `@State private var input` with `@Binding var input: String` // save(): if !pendingTag.isEmpty { draft.addTag(pendingTag, existing: ...) } // or reuse the editor's add logic To avoid duplicating the add rules, move them into a function on ItemDraft: mutating func addTag(_ raw: String, preferring stored: [String]) and call it from both the editor's onSubmit and save(). Because ItemDraft is plain Swift, the duplicate/spelling rules become unit-testable in Chapter 10. Note: save() must run this BEFORE it checks isValid and before it passes draft.tagNames to the repository.