سؤال

I'm trying to use the userVisibleDateTimeStringForRFC3339DateTimeString method that Apple documents here.

So first I created a separate class called jhsDateFormatter and first modified it from

- (NSString *)userVisibleDateTimeStringForRFC3339DateTimeString:(NSString *)rfc3339DateTimeString;

to - (NSMutableString *)userVisibleDateTimeStringForRFC3339DateTimeString:(NSMutableString *)rfc3339DateTimeString :(NSString *)rfc3339DateTimeFormatString;

so I could pass in a second parameter, which would be the desired date format string.

I then imported this new class into my view controller.m:

#import "jhsDateFormatter.h"

and called the method this way:

predicateMutableString = [userVisibleDateTimeStringForRFC3339DateTimeString:dateHolderMutableString :@"yyyy'-'MM'-'dd'"];

predicateMutableString is defined in the viewController.h and synthesized in the .m.

I got a build error: use of undeclared identifier 'userVisibleDateTimeSTringForRFC3339DateTimeString

So I commented out my modified version and used the original code and method signature in my class file:

    - (NSString *)userVisibleDateTimeStringForRFC3339DateTimeString:(NSString *)rfc3339DateTimeString;

and called it this way: enter image description here

I'm not sure why the method call isn't being accepted. I think I've matched up the data types.

Please let me know your ideas of what is awry.

Thanks

هل كانت مفيدة؟

المحلول

You probably want to declare your method like this:

+ (NSMutableString *)userVisibleDateTimeStringForRFC3339DateTimeString:(NSMutableString *)rfc3339DateTimeString formatString:(NSString *)rfc3339DateTimeFormatString;

(Note the + at the start, and the fact that the second argument is now named - it was blank in your code, which is valid but weird.)

Then you'd call it like this:

predicateMutableString = [jhsDateFormatter userVisibleDateTimeStringForRFC3339DateTimeString:dateHolderMutableString formatString:@"yyyy'-'MM'-'dd'"];

Where jhsDateFormatter the new class you've made.

In your example code, you're not calling the method on any object, which is why the compiler is complaining.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top