Re: Chapter 4 Pages 96 & 98 - Why is the method called before it is defined?

I would like to ask a question regarding the first app tutorial in the iOS Apprentice book. On page 96, it states the following:


➤ On to the good stuff! Add the following method below startNewRound() in ViewController.swift:

func updateLabels() {
   targetLabel.text = String(targetValue)
}

You’re putting this logic in a separate method because it’s something you might use from different places.


In the video tutorial (on this website) for the same app, I see that Ray Wenderlich places that code just beneath the startNewRound() function.

However, in the book on Page 98 (and in the video tutorial as seen here at 2:17), the updateLabels() method is then called from inside of the startNewRound() function - which is defined just above the updateLabels() method. If Swift code is executed from top to bottom, why (and how) is this method being called from within a function that is listed directly ABOVE where this method was actually defined?

Please help, thank you!

Nevermind, I found an answer elsewhere.

@kiwiandthemango Glad you sorted it out! Cheers! :]

This topic was automatically closed after 166 days. New replies are no longer allowed.