I have an NSDate category with following method
@implementation NSDate (DateUtility)
+(NSString *)dateTimeStringForDB {
NSDateFormatter *dateFormatForDB = [[NSDateFormatter alloc] init];
[dateFormatForDB setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *aDateStr= [dateFormatForDB stringFromDate:self];
[dateFormatForDB release];
return aDateStr;
}
@end
with this definition I receive a warning .
Incompatible pointer type sending 'Class' to parameter of type 'NSDate *'
However type casting self before assign it as argument suppresses this warning.
+(NSString *)dateTimeStringForDB
{
NSDateFormatter *dateFormatForDB = [[NSDateFormatter alloc] init];
[dateFormatForDB setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *aDateStr= [dateFormatForDB stringFromDate:(NSDate*)self];
[dateFormatForDB release];
return aDateStr;
}
Can we really not pass self as an argument in a category without typecasting it ? What is this feature dependent on , the compiler ? Looking for an answer before actually posting it as a question on SO I came across this, however I am still not clear as to what goes behind the scene.