Swift App UI Button Scope

Code Block
//
//  TowerAppApp.swift
//  TowerApp
//
//  Created by Besleaga Alexandru Marian on 5/17/21.
//
import SwiftUI
@main
struct TowerApp: App {
    var body: some Scene {
        WindowGroup {
            Text("5/17/21")
            Text(greeting + otherGreeting + name)
        }
    }
}
let greeting = "Welcome!"
let otherGreeting = " Have a nice time!"
let name = " Marie Curie"
Button("Sign In", action: signIn)
struct Button<Label> where Label : View{
    Button(action: signIn) {
        Text("Sign In")
    }
}

Cannot find
Code Block
'signIn'
in scope
Cannot find type
Code Block
'signIn'
' in scope

How to declare the UI Button ?

Don't you remember what I wrote before?

Ignore the word scope in the error message and find what you need to define.

When you get an error message like Cannot find 'signIn', it is signIn that you need to define, not Button.


But your code currently shown does not make sense.
  • Line 27...29: Text are not appropriate for WindowGroup

  • Line 47: You cannot write Button at the toplevel of the code

  • Line 51...59: Button is a predefined type in SwiftUI, it is not what you need to define

Swift App UI Button Scope
 
 
Q