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
Raphael Reiter
6,820 PointsDate is a type?
in the video Why are protocols Useful, we get that code :
import Foundation
enum EmployeeType { case manager case traditional }
class Employee { let name: String let address: String let startDate: Date let type: EmployeeType
init(name: String, address: String, startDate: Date, type: EmployeeType) {
self.name = name
self.address = address
self.startDate = startDate
self.type = type
}
}
QUESTION: I don't get the Date type. Where does it come from? I didnt know Date could be a type, such as String, Int Double... ?
2 Answers
Bien Pham
Courses Plus Student 4,478 PointsSwift comes with a bunch of classes/structures for you to use out of the box. One of them is Date or formerly known as NSDate. It has some properties and methods that come along with it so that you don't have to create it yourself all you have to do is use it. Try looking up the documentation to see what properties and methods it has and experiment with the different methods to see what it does to dates and formatting. So when you type in "Date" the IDE recognizes it as a reserved keyword and understands that your passing into your init parameters a Date Type.
Raphael Reiter
6,820 Pointsthanks