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 trialJuan Jimenez
4,389 PointsControlling 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
47,913 PointsHe 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
Juan Jimenez
4,389 PointsThat makes complete sense. Thank you for taking the time to provide such a thorough answer.