39.7 The Content View
As we have seen early in the chapter, the ContentView is passed an instance of the DocDemoDocument structure from within the App declaration:
ContentView(document: file.$document)
In the case of the DocDemo example, the ContentView binds to this property and references it as the content for a TextEditor view:
.
.
struct ContentView: View {
@Binding var document: DocDemoDocument
var body: some View {
TextEditor(text: $document.text)
}
}
.
.
When the view appears it will display the current string assigned to the text property of the document instance and, as the user edits the text, the changes will be stored. When the user navigates back to the document browser, a call to the fileWrapper() method will be triggered automatically and the changes saved to the document.