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

iOS Build a Blog Reader iPhone App Adapting Data for Display Formatting Dates with NSDateFormatter

Challenge Solution Wrong?

Hi,

I'm trying to complete this challenge, and I've tested my solution in Xcode and it works fine. I'm at the 3rd step where it asks me to create the date format, and it says that there is a compilation. I've copied my code back and forth between here and Xcode and it compiles just fine over there.

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

NSDate *today = [NSDate date];

NSTimeInterval tenDays = 60 * 60 * 24 * 10;
NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow:tenDays];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];

What am I doing wrong?

5 Answers

On further searching I found that someone else ran into the same issue.

I could have been clearer about my solution response. The problem is that the NSDateFormatter object is already declared. If you look further up in the code you'll see it. So just take out the declaration of dateFormatter (your second line) and you should be fine.

robert cioffi
robert cioffi
3,466 Points

I have the same issue as well, Im pretty sure my code is right, but the code checker finds issues: NSTimeInterval secondsPerDay = 60 * 60 * 24; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // Add your code below NSDate *today = [[NSDate alloc] init]; NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay*10]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"MM/dd/yyyy"];

unless there is something wrong with using the "/"?

robert cioffi
robert cioffi
3,466 Points

Oh man, so simple, thanks!

For me did it work that way:

NSTimeInterval secondsPerDay = 60 * 60 * 24;
NSTimeInterval secondsPerTenDays = secondsPerDay*10;

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];

// Add your code below
NSDate *today = [NSDate date];
NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerTenDays];

NSString *dateString = [dateFormatter stringFromDate:futureDate];