I have a Binding<Bool>
binding in a swiftUI view. Something along the lines of:
struct MyCoolView: View {
@ObservedObject var viewModel: ViewModel
var body: some View {
Text("Here is a cool Text!").sheet(isPresented: $viewModel.MyProperty) {
SomeModalView()}
}
}
I want the isPresented
to use the opposite boolean value of what is stored in the property using Boolean negation, the exclamation point !
operator, or some other method.
Swift wont let me just do something like
.sheet(isPresented: !$viewModel.MyProperty)
!$viewModel
gives the error:
Cannot convert value of type 'Bool' to expected argument type 'Binding<Bool>'
Any thoughts on how to deal with this?