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 Playlist Browser with Swift Working With Multiple View Controllers Recap of iOS Basics

Ga-eun Kim
Ga-eun Kim
2,558 Points

Why do we put the outlets/actions where we put them?

Why are IBOutlet and IBAction functions located where they are located? So, why do IBOutlets go above the viewDidLoad function and IBActions go under the didReceiveMemoryWarning function?

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello :

Well there is no specific answer to that, since it’s a preference. Now from what I have seen on tutorials, and on Apple’s forums this is a trend to do it that way, and it’s basically to have your code organized better. I usually do it this way:

// I put Variables/Constants, Labels & outlets on top

    override func viewDidLoad() {
        super.viewDidLoad()

        }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }

// And any IBAction and methods and segues if any, below the viewDidLoad.

This way I am more organized with my codes. I also use the // MARK: - "name” to mark different sections of my code and when searching for them is faster. alt text

Ga-eun Kim
Ga-eun Kim
2,558 Points

That makes sense. Thanks!