Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Weather App with Swift (Retired) Data Modeling With Structures Setting Icon Images

Don't you have to place functions before the init() method?

I'm curious about this and I'd love more information. At least during this test project, we're using functions that are created after the init() method within the init() method.

Given that the compiler reads our programs line by line, when the compiler reaches icon = weatherIconFromString(iconString), it is now referencing a function that has yet to be created, so therefore it wouldn't be able to carry out this process, right? Yet it does. Unless, of course, the init() method gets read last despite it being written before any of the functions.

Now if the init() method does get read last or is a special kind of method that gets executed when necessary, does this apply to any other methods?

1 Answer

Bram Grooten
Bram Grooten
2,415 Points

It doesn't matter in what order you define you functions. Whenever you call a function, the compiler searches through the file for the definition.

(maybe the compiler even searches through the whole project, because we create an instance of our Current struct with it's initializer method in another file, ViewController.swift)