UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 30 5.2 can't find errorMessage in Scope

Forums > 100 Days of SwiftUI

I have the problem that errorTitle, errorMessage and showingError can't be found in the Scope.

Anyone know why that might have hppened or what I must do?

func wordError(title: String, message: String) { errorTitle = title errorMessage = message showingError = true

I did create the @State private var: @State private var errorTitle = "" @State private var errorMesssage = "" @State private var showingError = false

2      

Hi Nealswiss96 Please can you put code inside ` code ` or use the icon </>. It make it easy to read. You should have

struct ContentView: View {
    @State private var usedWords = [String]()
    @State private var rootWord = ""
    @State private var newWord = ""

    @State private var errorTitle = ""
    @State private var errorMessage = ""
    @State private var showingError = false

    var body: some View {
      // some code in body
    }

    // some other methods

    func wordError(title: String, message: String) {
        errorTitle = title
        errorMessage = message
        showingError = true
    }
}

The error is that the compiler can find where you define the variables

2      

Thank you for your answer!

When looking at your code I realized that I had the block of code at the wrong place. Won't work in the ContentView_Previews

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.