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 trialNuttakit Luengwitayakorn
1,626 PointsMy code doesn't work
Please help to see why my code doesn't work
import Foundation
let secondsSinceBirth = NSTimeInterval(1200000000)
var dateOfBirth = NSDate(timeIntervalSince1970: secondsSinceBirth)
let dateFormatter = dateOfBirth.dateFormatter()
2 Answers
Stone Preston
42,016 Pointsyou incorrectly initialized the NSDateFormatter constant. Pasan walks you through creating an NSDateFormatter object at 4:55 of this video
you used
let dateFormatter = dateOfBirth.dateFormatter()
you called the initializer incorrectly. initializers use the same name as the class (NSDateFormatter) and the NSDateFormatter initializer takes no arguments.
you can initialize an NSDateFormatter by calling its initializer
import Foundation
let secondsSinceBirth = NSTimeInterval(1200000000)
var dateOfBirth = NSDate(timeIntervalSince1970: secondsSinceBirth)
let dateFormatter = NSDateFormatter()
Nuttakit Luengwitayakorn
1,626 PointsWhat about his second assignment I have put some like this but it still doesn't work too
let secondsSinceBirth = NSTimeInterval(1200000000) var dateOfBirth = NSDate(timeIntervalSince1970: secondsSinceBirth) var dateFormatter = NSDateFormatter()
dateFormatter.timeStyle = .Short dateFormatter.dateStyle = .Medium
var stringDate = dateFormatter.stringFromDate(dateOfBirth)
Nuttakit Luengwitayakorn
1,626 PointsNuttakit Luengwitayakorn
1,626 PointsWhat about his second assignment I have put some like this but it still doesn't work too
let secondsSinceBirth = NSTimeInterval(1200000000) var dateOfBirth = NSDate(timeIntervalSince1970: secondsSinceBirth) var dateFormatter = NSDateFormatter()
dateFormatter.timeStyle = .Short dateFormatter.dateStyle = .Medium
var stringDate = dateFormatter.stringFromDate(dateOfBirth)