如何创建仅在使用 SwiftUI 打开应用程序时出现的警报?

How do I create an alert which only appears when app is opened with SwiftUI?

我是应用程序开发新手,最近开发了一款名为 bullseye 的游戏。

我想在应用程序首次打开时显示提醒,向用户提供有关他们将要玩的游戏的说明。

我在没有按钮的情况下在 swiftUI 中创建此警报时遇到问题,想知道是否有人可以帮助我解决这个问题。

PS - 我正在使用 Xcode 11

谢谢

我不是 SwiftUI 专家,但这对我有用:

import SwiftUI

struct ContentView: View {

    // In the future, you can use this var to control whether or not to show an alert based on some other condition.
    @State var alertShouldBeShown = true

    var body: some View {
        // attach the alert to the last view in your view hierarchy
        Text("Hello, World!").alert(isPresented: $alertShouldBeShown, content: {

            Alert(title: Text("Alert:"),
                  message: Text("This is the alert. :)"),
                  dismissButton: Alert.Button.default(
                    Text("OK"), action: {

                        //

                  }
                )
            )
        })
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}