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 trialJames Godwin
936 PointsCreate 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
3,818 PointsI 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>
Wesley Ellis
3,818 PointsOn 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.
James Godwin
936 PointsJames Godwin
936 PointsSorry, 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.