views:

225

answers:

3

I'm getting this warning (below) when trying to use NSDateFormatter. I am importing in my .h file so what is the prob? (Oh, and the same method generates an error (unrecognized selector sent...))

Here is the WARNING:

warning: no '-initWithDateFormat:allowNaturalLanguage:' method found

Here is the Code:

NSDateFormatter *myFormatter = [[NSDateFormatter alloc] initWithDateFormat:@"EEE, dd, MMM yyyy HH:mm:ss ZZZ" allowNaturalLanguage:NO];

NSDate *date = [myFormatter dateFromString:@"Mon, 01 Feb 2010 20:25:37 +0000"];
NSLog(@"Time interval %d",[date timeIntervalSinceNow]);
+2  A: 

The iPhone SDK hasn't got this init method, only the Mac OS X SDK has it. You have to use plain [[.. alloc] init] and set the properties yourself.

Georg
+3  A: 

Like Georg says, initWithDateFormat:allowNaturalLanguage is allowed only on Mac OS X and not on iPhone.

You can use NSDateFormatter on iPhone like this:

NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
formatter.dateFormat = @"yyyy-d-M";
Chintan Patel
A: 

Sorry, I think it should be...

NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];    
[formatter setDateFormat:@"yyyy-d-M"];
zinc
LOLZZ.. You remind me of my first month with Objective C. ;)
Chintan Patel
Sorry I'm confused??
zinc