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


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!