I'm playing with a simple document-based application with TextEditor for macOS. In Cocoa, NSViewController can call updateChangeCount(_:) to clear document changes in NSDocument. I wonder SwiftUI's View has access to the same function? Hopefully, I would like to manually set the change count to zero if the user clears text in TextEditor. I bet SwiftUI doesn't have it. Thanks.
import SwiftUI
struct ContentView: View {
@Binding var document: SampleDocumentApp
var body: some View {
VStack {
TextEditor(text: $document.text)
.onChange(of: document.text) { _, _ in
guard !document.text.isEmpty else {
return
}
// clear change count //
}
}
.frame(width: 360, height: 240)
}
}