Created
October 3, 2019 11:00
-
-
Save NeoTeo/30c0b5cadf45fe3d47641c2758632a23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just lurking, that's because it's expecting an optional Bool.