Xcode 版本 11.0 (11A420a)(.presentation)弃用?

Xcode Version 11.0 (11A420a) (.presentation) deprecate?

我有这个脚本:

List {

        //code

    }.presenation($displayAlert) {
        Alert(title: Text("Start1"), message: Text("other...."), dismissButton: .default(Text("Go!")))
    }

我收到错误:

"Protocol type 'Any' cannot conform to 'View' because only concrete types can conform to protocols"

我认为 .presentation 在版本 11.0 (11A420a) 上已弃用

我该如何解决这个错误?

谢谢!

要显示警报,您需要使用 .alert 修饰符,因为 .presentation 修饰符在 Beta 4 中已弃用。

这里是一个简单的例子,展示了如何使用它。

struct ContentView: View {

    @State var showAlert = false

    var body: some View {

        List {

            Button(action: {
                self.showAlert.toggle()
            }) {
                Text("press me")
            }

        }.alert(isPresented: $showAlert) {
            Alert(title: Text("Title"), message: Text("Message"), dismissButton: .default(Text("OK!")))
        }
    }
}

您可能还想考虑更新您的 Xcode 版本,因为今天发布了 11.2