“警告:'<class>'可能无法响应'&lt; [ - | +] FUNCTION&gt;'”目标C / Xcode编译器警告</class>

时间:2010-03-09 18:58:33

标签: objective-c xcode compiler-warnings

我想出了这个,但认为它值得自己的问题答案对。

我是Xcode和Objective C的新手,并了解其各种怪癖。例如,当我尝试编译以下代码时,编译器警告“警告:''可能无法响应'&lt; [ - | +] FUNCTION&gt;'”,这些代码都出现在我的实现文件中,因为我希望创建一个此类的私有静态实用程序函数:

// Here's the function declaration in the implementation file (I don't want it in the header)
+(void)authenticationRedirectTo:(NSURL *)url WithRelayState:(NSString *)relayState AndSAMLResponse:(NSString *)samlResponse {
...
}

...

// Later on, here's a call to that same function:
[CnaCalendarController authenticationredirectTo:formActionURL WithRelayState:relayState AndSAMLResponse:SAMLResponse];
...

编译时,会产生上面的警告。接下来,我将发布我的决议。随意提供您的想法!

4 个答案:

答案 0 :(得分:3)

如果您真正想要的是一个私有方法,也就是说,您不希望该方法位于头文件中,那么我喜欢使用Category来完成此操作。我只是在我的实现上面定义了类别。

// Enforce private methods by putting them in a category.
@interface YourClass (PrivateMethods)

+(void)authenticationRedirectTo:(NSURL *)url WithRelayState:(NSString *)relayState AndSAMLResponse:(NSString *)samlResponse;

@end

@implementation YourClass

+(void)authenticationRedirectTo:(NSURL *)url WithRelayState:(NSString *)relayState AndSAMLResponse:(NSString *)samlResponse {
...
}
@end

现在,你的实现方法的顺序并不重要,哪个好,所以你可以正确地“#pragma mark”

答案 1 :(得分:1)

问题在于你的方法调用:

[CnaCalendarController authenticationredirectTo:formActionURL WithRelayState:relayState AndSAMLResponse:SAMLResponse];

请注意,“authenticationredirectTo:...”中的第一个“r”是小写字母,但您已将其声明为“authenticationRedirectTo:...”,其大写字母为“R”。鉴于此,编译器抱怨它无法找到您正在调用的方法的声明并不奇怪。代码也可能在该行崩溃,因为没有定义小写“r”的方法。

答案 2 :(得分:0)

我认为问题在于,您在调用此函数后声明了该函数。虽然编译它却找不到它。

答案 3 :(得分:-3)

好的,这是我承诺的解决方案:

问题1:在处理完源代码中的调用之后出现函数声明或实现时,Xcode会产生错误警告。就我而言,它们位于同一个文件中,因此我可以在调用之上转移到函数实现。

还要检查导入的顺序,以确保在调用导入之前导入此类函数。我没有看到这个,但看到其他帖子就是这种情况。

问题2:似乎Xcode对函数名的 LENGTH 有一些限制。缩短我的功能名称,如下面的剪辑所示,解决了这个问题。我显然会选择更有意义的东西。

// Here is the warning function commented out and a *shorter* name in place.
//+(void)authenticationRedirectTo:(NSURL *)url WithRelayState:(NSString *)relayState AndSAMLResponse:(NSString *)samlResponse {
+(void)X:(NSURL *)url Y:(NSString *)relayState Z:(NSString *)samlResponse {

希望这可以帮助您解决问题。如果它有用,请不要忘记投票。