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.


Code Challenge: Hung up on NSDateFormatter

So I'm beating my head against the wall. I can't figure this one out. I'm on the step:

Create a date format using the given 'dateFormatter' variable to display any date with the format of '02/29/2012'. Don't worry about using it for now, just set up the formatter.

And here is my answer:

NSTimeInterval secondsPerDay = 60 * 60 * 24;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// Add your code below

NSDate *today = [NSDate date];
NSTimeInterval timeInterval = 60 * 60 * 24 * 10;
NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];
// Also tried [dateFormatter setDateStyle:NSDateFormatterShortSytle];

What am I missing?

1 Answer

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

As stated in the challenge the dateFormatter variable is already declared in the second line you need not declare it again (on your second last line).

So simple, yet embarrassing!