RexOnRoids
RexOnRoids

Reputation: 14040

Why is a documented NSDateFormatter init method not getting recognized?

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]);

Upvotes: 1

Views: 1384

Answers (3)

Chintan Patel
Chintan Patel

Reputation: 3165

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";

Further reading:

Upvotes: 5

curv
curv

Reputation: 3844

Sorry, I think it should be...

NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];    
[formatter setDateFormat:@"yyyy-d-M"];

Upvotes: 0

Georg Schölly
Georg Schölly

Reputation: 126105

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.

Upvotes: 2

Related Questions