Most of the solutions I see are partaining to SwiftUI where a string can be passed as a Binding String like this
TextField("", $text)
But in this case, it's purely on Swift... I have this code below
final class Coordinator: NSObject, UITextViewDelegate {
var text: Binding<String>
init(text: Binding<String>) {
self.text = text
}
func myFunc(){
let string = "my string" // a dynamically created String
self.text = string // This throws an error that I cannot assign value type of string to Binding<String>
}
}
How can I get to convert String to Binding<String>?
Bindingis only for SwiftUIViews, it doesn't work in a class, leave it in the parentTextFieldin SwiftUI, so the other end of the data binding is coming from a SwiftUI page... My purpose of doing this is that I want to be able to edit some of the text as the user is typing and display it back to the user.ObservableObject, this is probably what you want.