I'm starting to develop for the iPhone, and so I look at various tutorials online, and also try different things. I'm currently trying to create a countdown to midnight. To get the number of hours, minutes and seconds, I do the following (which I found somewhere):
NSDate* now = [NSDate date]; int hour = 23 - [[now dateWithCalendarFormat:nil timeZone:nil] hourOfDay]; int min = 59 - [[now dateWithCalendarFormat:nil timeZone:nil] minuteOfHour]; int sec = 59 - [[now dateWithCalendarFormat:nil timeZone:nil] secondOfMinute]; countdownLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hour, min,sec];
However, in every place where I use -dateWithCalendarFormat:timeZone: I get the following error:
warning: 'NSDate' may not respond to '-dateWithCalendarFormat:timeZone:' (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.) warning: no '-hourOfDay' method found error: invalid operands to binary - (have 'int' and 'id')
It seems like something very simple. What am I missing?
In addition, I noticed in different places and at different times, an asterisk (*) is either immediately after the NSDate* now , or right before the NSDate *now variable. What is the difference in two and why are you using one against the other?
objective-c cocoa nsdate
Jason Jul 01 '09 at 17:25 2009-07-01 17:25
source share