Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDateFormatter missing methods...am I missing an import

I'm an IOS newbie but am trudging forward as best as I can.

I searched this site and google but found no answer to my problem, or even any parallel.

I am using a method declared in the documentation (I actually borrowed this line from a website on obtaining the timezone offset in hours):

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] initWithDateFormat:@"zzz" allowNaturalLanguage:NO];

But the compiler error message says:

No visible @interface for 'NSDateFormatter' declares the selector 'initWithDateFormat:allowNaturalLanguage:'

When I try the autocomplete, it does not suggest this particular init method, only init and initWithCoder.

Am I missing some required import? I thought this was a part of the Foundation.h.

Any help would be greatly appreciated.

Thanks.

Jason

like image 994
Casey Perkins Avatar asked Nov 29 '25 16:11

Casey Perkins


1 Answers

The method NSDateFormatter initWithDateFormat:allowNaturalLanguage: is not part of iOS. That method is only available for the Mac. For iOS do:

NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"zzz"];
like image 110
rmaddy Avatar answered Dec 02 '25 06:12

rmaddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!