samedi 26 septembre 2020

SwiftUI Why can't I use an Alert within an if statement

I'm currently working through the #100daysofswiftUI and have a quick question regarding the use of alerts within if statements. This particular task is at the end of the second project.

Please be clear about any explanations. I'm a beginner!'m 100% certain all external parameters referenced in the equation are correct.

I

Here is the code:

.alert(isPresented: $showingScore) {
        if x == 1 {
            Alert(title: Text(scoreTitle), message: Text("The correct answer was \(countries[correctAnswer])"), dismissButton: .default(Text("Restart")) {
                    self.askQuestion()
            })
        }
    }

I feel like this code should work however I have a yellow alert over the Alert line saying "Result of 'Alert' initializer is unused"

I don't know what this means, how can I fix this?

Aucun commentaire:

Enregistrer un commentaire