Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot assign to property: 'absoluteString' is a get-only property

I’m trying to fill the textfield with the current web page url but i’m getting this error

Cannot assign to property: ‘absoluteString’ is a get-only property

         @ObservedObject var navigationState = NavigationState()

         //Address bar
         TextField("username", text: Binding<String>(
            get: {self.navigationState.url?.absoluteString ?? ""},
            set: {self.navigationState.url?.absoluteString = $0 }))
            .textFieldStyle(RoundedBorderTextFieldStyle())
            .padding(.top, 1.5)
            .onSubmit {
                ............
                }

Navigation State

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class NavigationState : NSObject, ObservableObject {
    @Published var url : URL? = nil

    let webView = WKWebView()
    

}

    


extension NavigationState : WKNavigationDelegate {
    func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
        self.url = webView.url
        
    }
}

>Solution :

It should be created URL from string, like

 TextField("username", text: Binding<String>(
    get: {self.navigationState.url?.absoluteString ?? ""},
    set: {self.navigationState.url = URL(string: $0) }))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading