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
Pierre Smith
11,842 Pointshow do I use separate functions into different .swift files and use them in the main viewController.swift
I want to separate different modules of my program into different swift files and then run it all under one viewDidLoad. how do I do that?
Pierre Smith
11,842 Pointsi'm not sure how it would work for what I want. Basically I want to put my locationManager:DidUpdateLocation and stuff similar to that in another file. Every time I try to use Viewcontroller.lblCurrentLocation ="foo" it says ViewController.type does not have a member named lblCurrentLocation
Nick Janes
5,487 PointsAre you importing the class? Also make sure you define lblCurrentLocation in your classes .h file so it can be accessed by the view controller.
2 Answers
Michael Liendo
15,326 PointsYou just type in the "@" sign followed by the person's name :)
Michael Liendo
15,326 PointsNick Janes thank you for trying to help, but in Swift there are no headers or import statements like in objective-C. All added files in the app are automatically imported. Pierre Smith to answer your question, you would want to create an instance of your class as a stored variable.
So if you have another class with functions you'd like to access in--for example, your mainViewController, then in your mainVC you'd write something like this, most likely at the top as a property:
var newInstance = NameOfOtherClass
and to access it's functions and properties in your mainVC, you would simply use dot notation:
newInstance.foo.count = someInt
hope this helps :) and glad to see your focussing on organizing your project!
Nick Janes
5,487 PointsOops, I didn't see it was Swift. My bad! Haha
Pierre Smith
11,842 PointsThank You so much Nick and Michael. I have one small off topic question, how do you create those linked Names?
Nick Janes
5,487 PointsNick Janes
5,487 PointsDo you know how to work with classes? You could make new classes and then import them into your view controller and then use them there.