Skip to content

SwiftUI Text Binding One-Way Only #37

@badepaz

Description

@badepaz

Really love this framework; great job on it! I have an app that I'm building that displays some JSON return values from API calls. It's sort of like a native iOS/macOS demo app to show off the features of a backend API service. So my need wasn't really an editor but a pretty printed JSON output view. The app is SwiftUI based, and I noticed that the binding for the text only works one way. If I change the @State string in the SwiftUI view programmatically (such as when my API call returns with the JSON data and puts it in the state property) the SourceCodeTextEditor view doesn't update.

struct AppRootView: View {
  
   @State private var editorText = ""

   var body: some View {
      VStack {
         Button("Insert JSON") { 
            editorText = "{ \"value\": \"Hello, World!\"}" 
            // Does not update the contents of the SourceCodeTextEditor
         }
      
         SourceCodeTextEditor(text: $editorText)
      }
   }

}

It would appear that there is no observer attached to the binding on the UIKit/AppKit side of the bridge to synchronize the underlying NS(UI)TextView.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions