Question re function order

On line 55 of the attached image from an iOS tutorial, the author defines a method called updateLabels().

However, immediately above, on line 52, in the startNewRound() function, the updateLabels() method is being called from inside of the startNewRound() function.

If Swift code is executed from top to bottom, why (and how) is this method being called from within the startNewRound() function, when the updateLabels() method isn’t yet defined until after the function from which updatelabels() is being called?

Please help, thank you!

Right, so conceptually all of those functions are part of a class. Within each function the order matters for defining generally how the logic goes. Inside of the class body though, all of the functions are available at the same time. This means you can do things like have functions call other functions from the class, or even themselves.

Basically, the code inside of the body of a class / struct does not respect order of functions or variables.

1 Like

Thank you for this, now I understand clearly.

Terms of Service

Privacy Policy

Cookie Policy