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.


Create an NSDate object called 'today' that represents today's date.

I can't get past the code challenge and not sure what I'm doing wrong. The question: Create an NSDate object called 'today' that represents today's date and my answer is below...

NSTimeInterval secondsForTenDays = 60 * 60 * 24 * 10; NSDate *futureDate = [[NSDate alloc]init]; futureDate = [NSDate dateWithTimeIntervalSinceNow:secondsForTenDays];

and I get "Bummer! Compilation Error!" but I can't see what I'm doing wrong. Any ideas?

2 Answers

Wesley Ellis
Wesley Ellis
3,818 Points

I don't see an NSDate object in your code that is named "today".

Try <code>NSDate *today = [NSDate date];<code>

If you ever need help, try looking at the documentation for the class and/or method you are trying to use. Like <link>"https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html#//apple_ref/occ/clm/NSDate/date"</link>

Sorry, I got the questions mixed up. The question is "Using NSDate create a date object that is 10 days from today and call it 'futureDate'"

Thanks for your help.

Wesley Ellis
Wesley Ellis
3,818 Points

On the same page, there is another method listed: it's prototype looks like this: <code>dateWithTimeIntervalSinceNow</code>

So <code>NSDate *futureDate =[dateWithTimeIntervalSinceNow:10*24*60*60];</code>

or: <code>NSDate *futureDate = [dateWithTimeIntervalSinceNow: 864000];</code>

Also, note that there is no need to allocate memory and initiate the instance. That is all taken care of by the dateWithTimeIntervalSinceNow method. But you must remember to include the * in your declaration of futureDate. This tells the compiler that futureDate is actually a pointer to a location in memory of the object that is returned by dateWithTimeIntervalSinceNow, which is of class NSDate. Hope that does it for you.