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 trialJoe Scotto
8,282 PointsWhy is the FactModel.swift file not included in some way withing ViewController.swift?
I'm coming from a PHP background and whenever referencing a class in another file you will need to either pass it in, autoload it, or use some other method to reference that file. How is this handled in swift? Why am I able to just create a file, and then reference that files class from withing another?
1 Answer
Joe Beltramo
Courses Plus Student 22,191 PointsAs far as I know, it is Xcode's compiler. Xcode looks within all the files in the project and automagically imports what is needed, allowing you to call a method from another file. It is related to your project acting as its own namespace/module and all files in the project are pieces of said module.
Joe Beltramo
Courses Plus Student 22,191 PointsJoe Beltramo
Courses Plus Student 22,191 PointsI will add, that not everything is accessible to the whole of your project. It is all dependent on access control (public/private/internal) similar to PHP's access control but scoped to files I believe rather than the instance itself.