[英]Getting Use of Undeclared Identifier error with imported method
I'm trying to use the userVisibleDateTimeStringForRFC3339DateTimeString method that Apple documents here . 我正在尝试使用Apple 在此处记录的userVisibleDateTimeStringForRFC3339DateTimeString方法。
So first I created a separate class called jhsDateFormatter and first modified it from 因此,首先我创建了一个名为jhsDateFormatter的单独的类,并首先从
- (NSString *)userVisibleDateTimeStringForRFC3339DateTimeString:(NSString *)rfc3339DateTimeString;
to - (NSMutableString *)userVisibleDateTimeStringForRFC3339DateTimeString:(NSMutableString *)rfc3339DateTimeString :(NSString *)rfc3339DateTimeFormatString; 到-(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. predicateMutableString在viewController.h中定义,并在.m中合成。
I got a build error: use of undeclared identifier 'userVisibleDateTimeSTringForRFC3339DateTimeString 我收到一个构建错误:使用未声明的标识符'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: 并这样称呼它:
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. 其中jhsDateFormatter是您创建的新类。
In your example code, you're not calling the method on any object, which is why the compiler is complaining. 在示例代码中,您没有在任何对象上调用该方法,这就是编译器抱怨的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.