1
warning: 'NSDate' may not respond to '+currDate'

Above is a warning message when I compile the following code:

-(IBAction)getDate:(id)sender   {
currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[ dateFormatter setDateFormat:@"yyyy-MM-dd"];
    strCurrDate = [dateFormatter stringFromDate:[NSDate currDate]];
displayDate.text = strCurrDate;
[dateFormatter release];

}
I'm just trying to get the current date and display it in a label called displayDate. Using the debugger I can see that the date is never converted to a string and stored into strCurrDate.

The warning message is on the line where I try to use stringFromDate

Can anyone see why this isn't working properly? Any help would be greatly appreciated.

I also currDate is my header file:

 NSDate         *currDate;
cruzzzin
  • 33
  • 1
  • 3

1 Answers1

1

That's because currDate is not a class method of NSDate instead it is a property of your class. So this line:

strCurrDate = [dateFormatter stringFromDate:[NSDate currDate]];

should be:

strCurrDate = [dateFormatter stringFromDate:currDate];
Jonathan.
  • 53,997
  • 54
  • 186
  • 290