Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Swift

Controlling Custom Views

Hey guys

In the swift course, building a vending machine app chapter, controlling custom views lesson/video, Pasan creates a new a view controller and creates a cocoa Touch class. He then gives it the sub class DepositController.

My question is, why doesn't he use a swift file for this? He never explained why he chose a cocoa touch class.

2 Answers

Michael Hulet
MOD
Michael Hulet
Treehouse Moderator 47,831 Points

He did use a Swift file, he was just implementing a subclass of a Cocoa Touch class within it. The language he's using to write is Swift, but the iOS SDK (all the stuff in Founation/UIKit/etc. like UIView/NSAttributedString/etc.) is called Cocoa Touch. In Xcode, the "Swift file" template provides you with a blank Swift file, but the "Cocoa Touch class" template provides you with a mostly-blank Swift (or Objective-C, if you want) file with a basic class/subclass already defined. There's really no technical difference between the two besides the fact that the "Cocoa Touch class" template fills in a bit more for you to start so you don't have to write it yourself

That makes complete sense. Thank you for taking the time to provide such a thorough answer.