'Cannot assign value of type 'Binding<String>' to type 'String'

I get the following error:

Cannot assign value of type 'Binding' to type 'String'

How to fix it? Please help.

struct TextFieldWithClear: View {
    var title: String
    @Binding var text: String
    
    init(_ title: String, text: Binding<String>) {
        self.title = title
        self.text = $text // ERROR: Cannot assign value of type 'Binding<String>' to type 'String'
    }
    
    var body: some View {
        HStack {
            TextField("Title", text: $text)
            Image(systemName: "xmark.circle.fill")
                .onTapGesture { text = "" }
        }
    }
}


Solution 1:[1]

struct TextFieldWithClear: View {
    let title: String
    @Binding var text: String
    
    var body: some View {
        HStack {
            TextField("Title", text: $text)
            Image(systemName: "xmark.circle.fill")
                .onTapGesture { text = "" }
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 malhal