【发布时间】:2020-10-08 21:29:28
【问题描述】:
在 SwiftUI 中,我有一个如下所示的结构。有一个绑定变量是一个布尔值。对于预览版,Xcode 期望用什么来代替 Binding<Bool> 占位符? true 和 false 返回错误:“无法将 'Bool' 类型的值转换为预期的参数类型 'Binding'”。
import SwiftUI
struct DetailShellView : View {
@Binding var isPresented: Bool
var testMessage: String
var body: some View {
VStack {
Button(action: {
self.isPresented = false
print("variable message: \(self.testMessage)")
}) {
Text("Close modal view")
}
Text(testMessage)
}
}
}
struct DetailShellView_Previews: PreviewProvider {
static var previews: some View {
DetailShellView(isPresented: <#Binding<Bool>#>, testMessage: "donuts")
}
}
【问题讨论】: