views:

528

answers:

3

I figured this one out, yet thought it worthy of its own question answer pair.

I'm new to Xcode and Objective C, and getting to know its varied eccentricities. For instance, the compiler warning "warning: ''may not respond to '<[-|+]FUNCTION>'" appears when I try to compile the following code, which all appears in my implementation file since I desire to create a private static utility function for this class:

// 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];
...

When compiled, this produces the warning above. Next, I'll post my resolution. Feel free to contribute your ideas as well!

A: 

OK, here's my solution as promised:

Problem 1: Xcode will generate erroneous warnings when a function declaration or implementation appears after the call in processed source code. In my case, they are in the same file so I was able to move to function implementation above the call.

Also check the order of your imports to ensure such a function is imported before an import that calls it. I didn't see this but saw other posts where this was the case.

Problem 2: It seems Xcode has some limitations on the LENGTH of function names. Shortening my function name as shown in the snip below resolved the issue. I'll obviously pick something more meaningful.

// 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 {

Hope this helps you with your troubles. Don't forget to vote this answer if it is useful.

EC_Johnson2000
I agree with your solution to your problem 1: The C language cares about the order. It's not erroneous, it's just part of the specification of C! I think there's something wrong with your solution to Problem 2. The length of the name `authenticationRedirectTo:WithRelayState:AndSAMLResponse:` is not that long in the standard Cocoa. Did you really type it correctly, keeping the capital/lower case distinction? What was the source file and the warning?
Yuji
Xcode definitely doesn't have a limitation on the length of function names. You've made an error.
Rob Keniger
+2  A: 

If what you really want is a private method, that is, you don't want the method to be in the header file, then I like to use a Category to accomplish this. I just define the category above my implementation.

// 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

Now, it doesn't matter what the order of your methods in your implementation is which is nice so you can properly "#pragma mark"

Randy Simon
You don't even have to name your category. `@interface YourClass ()` should work.
Yuji
A: 

Thank you for this, it really helped me understand why I was full of warning messages. I am used to program in PHP and working in Objective-C only for a week and I was getting crazy trying to debug the warning messages

TWiN