Can someone explain this syntax?
static var previews: some View {
Toast(isToastVisible: .constant(true))
}
What’s .constant(true)?
Especially: Why not Toast(isToastVisible: true)?
>Solution :
The isToastVisible property of your View is not a Boolean, it’s a Binding<Boolean>, which allows SwiftUI to observe when changes to your view happen, and update the UI as necessary.
Bindings are designed to allow you to update the value they wrap, but when that’s not necessary, like on a preview, you can initialise them using a constant instead.