Skip to content

Instantly share code, notes, and snippets.

@NeoTeo
Created October 3, 2019 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeoTeo/30c0b5cadf45fe3d47641c2758632a23 to your computer and use it in GitHub Desktop.
Save NeoTeo/30c0b5cadf45fe3d47641c2758632a23 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State var a: Bool = false
var body: some View {
A(a: $a)
}
}
struct A : View {
@Binding var a: Bool
var body: some View {
// Fails with "Cannot convert value of type 'Binding<Bool>' to expected argument type 'Binding<Bool?>'"
// ^~~~
//B(a: $a)
B(a: Binding.constant(self.a))
}
}
struct B : View {
@Binding var a: Bool?
var body: some View {
if a == nil {
return Text("a is nil")
} else {
return Text("a is \(a! ? "true" : "false")")
}
}
}
@mkaulfers
Copy link

Just lurking, that's because it's expecting an optional Bool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment