How to Auto load info to label while open .app by swift code

Viewed 33

I am starting to learn swift code, with this code after entering your name and pressing the button will appear greeting information. I want to not need to press the button, when I open the application, can it run this code by itself? with the words "Hello World!"

var name = nameField.stringValue
if name.isEmpty {
  name = "World"
}
let greeting = "Hello \(name)!"
helloLabel.stringValue = greeting
1 Answers

Put the code into viewDidLoad.

override func viewDidLoad() {
    super.viewDidLoad()
    
    ...
}
Related