在 SwiftUI
中,我发现了 Alert
类型。但我想知道如何使用 presentation
方法显示它。
初始化一个 Alert
很容易。但如何使用绑定(binding)?
struct ContentView : View {
var body: some View {
Button(action: {
// Don't know how to use the `binding` below
presentation(binding, alert: {
Alert(title: Text("Hello"))
})
}, label: {
Text("asdf")
})
}
}
绑定的类型为
Binding<Bool>
。