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
Sean Lee
5,196 Points( Extra Credit ) Blog Reader iPhone App : Instead of dates display the age of a blog post.
I'm trying to complete this extra credit and I've managed to print in the console the Age of the post. I try to return secondsBetween back but there is an error "'NSTimeInterval' (aka 'double') to parameter of incompatible type 'NSDate *'"
Does anyone provide guidance on how i can fix my code? I think because i'm trying to return a NSTimeInterval which is causing the problem but I'm still trying to learn and get comfortable calling methods from classes.
-(NSString *) formatDate{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *tempDate = [dateFormatter dateFromString:self.date];
NSDate *today = [NSDate date];
NSTimeInterval secondsBetween = [today timeIntervalSinceDate:tempDate];
int numberOfDays = secondsBetween / 86400;
NSLog(@"# of days: %d", numberOfDays);
[dateFormatter setDateFormat:@"MMM-dd-yyyy"];
return [dateFormatter stringFromDate:secondsBetween];
}
2 Answers
Stone Preston
42,016 PointsstringFromDate takes a NSDate object as an argument, but you are passing it an NSTimeInterval (which is a double)
Robert Bojor
Courses Plus Student 29,439 PointsYou can have a look at my implementation, to get the idea. I can also provide the PHP and javascript versions if someone is interested and doesn't want to recode it.