I want to have a modal view whenever the avatar is pressed and selected. But when using the binding var, there is no way to know whether it is an empty string..
Codes below:
struct SelectAvatarView: View {
var role: String
@State var selectedAvatar: String?
var body: some View {
NavigationView{
ZStack {
BackgroundView()
VStack {
TitleTextView(title: "Choose your avatar:")
if role == "Parent" {
ParentAvatarView(selectedAvatar: $selectedAvatar)
}
else{
ChildAvatarView(selectedAvatar: $selectedAvatar)
}
Spacer()
}.padding()
.sheet(isPresented: !(self.$selectedAvatar.isEmpty) ) { SimpleTestView()}
}
}
}
}
Problem is I don't know how to check the binding var $selectedAvatar
. no matter what I wrote, errors are:
Cannot convert value of type 'Binding<Bool>' to expected argument type 'Bool'
Help!!! and Thanks!!
I don't know how your view architecture.
But here you can fix your compile error by bellow code.