How to fix “Cannot convert value of type 'String' to expected argument type 'Binding<String>'”
About 2 min
How to fix “Cannot convert value of type 'String' to expected argument type 'Binding<String>'” 관련
SwiftUI by Example
Back to Home
How to fix “Cannot convert value of type 'String' to expected argument type 'Binding'” | SwiftUI by Example
How to fix “Cannot convert value of type 'String' to expected argument type 'Binding'”
Updated for Xcode 15
SwiftUI’s components expect to have two-way bindings to properties, using something like @State
or @ObservedObject
. This error occurs because you tried to create an interactive component without a binding, such as this:
TextField("Enter your name", text: name)
To fix the problem, make sure your property is marked with @State
, like this:
@State private var name = ""
Now create your component using a two-way binding, like this:
TextField("Enter your name", text: $name)
Similar solutions…
How to fix “Cannot convert value of type 'String' to expected argument type 'Text'” | SwiftUI by Example
How to fix “Cannot convert value of type 'String' to expected argument type 'Text'”
How to fix “Cannot convert value of type '() -> ()' to expected argument type '() -> _'” | SwiftUI by Example
How to fix “Cannot convert value of type '() -> ()' to expected argument type '() -> _'”
How to fix “Cannot assign to property: 'self' is immutable” | SwiftUI by Example
How to fix “Cannot assign to property: 'self' is immutable”
How to fix “Missing argument for parameter 'content' in call” | SwiftUI by Example
How to fix “Missing argument for parameter 'content' in call”
How to fix “Function declares an opaque return type, but has no return statements in its body from which to infer an underlying type” | SwiftUI by Example
How to fix “Function declares an opaque return type, but has no return statements in its body from which to infer an underlying type”