2

This might be a super simple bug, but my eyes are practically bleeding from trying to hunt it down. At first, I thought ARC might be playing a role, but now its completely disabled, and I'm still getting the bug.

I have a UMLLanguageProtocol protocol which defines a static method

+(NSArray *)methodFormatComponents;

I am trying to call that method within a function, but it is not being recognized by Xcode ("no known class method selector").

Here is the code where I am trying to use it:

#import "UMLLanguageProtocol.h"

@implementation UMLMethod

@dynamic documentation;
@dynamic name;
@dynamic umlClass;

+(void)validPortionOfMethod:(NSString *)method inLanguage:(Class<UMLLanguageProtocol>)language {
    [language methodFormatComponents];   <-- Error: No known class method selector 
}

@end

and the protocol itself, defined in UMLLanguageProtocol.h

#import <Foundation/Foundation.h>

#define VISIBILITY_SPECIFIER_COUNT 6

@class UMLMethod;
@class UMLAttribute;
@class UMLParameter;

typedef enum {
    PUBLIC, 
    PRIVATE, 
    PROTECTED, 
    PACKAGE,
    DERIVED,
    STATIC
} visibility;

@protocol UMLLanguageProtocol

/* 
 * Language Specifiers
 */
+(NSArray *)nativeDataTypes;

// Return a 6 item array with YES if the language supports that visibility
// specifier at the given index, and no if it doesn't.
+(NSArray*)visibilitySpecifiersForVariables;
+(NSArray*)visibilitySpecifiersForMethods;

/*
 * Parsing Methods
 */
// Returns a regex string that defines a validly formatted method
+(NSString *)methodFormat;
+(NSArray *)methodFormatComponents;

@optional
+(NSString*)documentationCommentFromText:(NSString*)comment;
+(NSString*)scaffoldTextFromMethod:(UMLMethod*)method;
+(NSString*)scaffoldTextFromParameter:(UMLParameter *)parameter;
+(NSString*)scaffoldTextFromAttribute:(UMLAttribute*)attribute;

+(NSArray *)additionalCommonDataTypes;
+(NSString *)defaultRootObject;

@end

Seriously, I'm losing hair as I write this... please help!


UPDATE: Actually, it seems the error is in two parts in the issue navigator. The first part is "Automatic Reference Counting Issue" and the second line is "No known class method for selector". That's odd, what could this possibly have to do with ARC?!

Plastech
  • 757
  • 6
  • 17
  • Have you inspected the language argument that is being passed into `validPortionOfMethod` and confirmed that the class does indeed implement the `methodFormatComponents` class method? Also, try changing to `inLanguage:(id)language` instead of `inLanguage:(Class)language` – Jeremy Jan 12 '12 at 00:58
  • I can't reproduce this. I seem to be able to do exactly what you're doing perfectly fine with no errors. Care to share your compiler command line to see if there's any differences? – mattjgalloway Jan 12 '12 at 01:15
  • @Jeremy if he does that, he will also have to change how he calls the methodFormatComponents method. FWIW, I can add the UMLLanguageProtocol.h file to a project and then stick your validPortionOfMethod method in another class (e.g. AppDelegate) and it compiles just fine for me. – UIAdam Jan 12 '12 at 01:17
  • Are you calling validPortionOfMethod from anywhere? What does that code look like? – UIAdam Jan 12 '12 at 01:41
  • I haven't implemented it yet. But it will be a class method of every class that follows the UMLLanguageProtocol. That should be a runtime bug though, not a compile time one. – Plastech Jan 12 '12 at 01:47
  • This has to be an ARC issue somehow. I added an instance method -(void)test to the protocol and did a simple test in the implementing class (NSObject) *test; [test test]; and am getting the same error. Again prepended with "ARC Issue" – Plastech Jan 12 '12 at 01:49
  • It compiles just fine for me with and without ARC. So something else strange must be going on. That sort of error with ARC usually means it can't see the definition of the class/protocol to find the method signature. And it would be a warning in non-ARC land normally. It's an error in ARC because ARC needs to know the method signature to do it's business. It's not specifically an ARC error though. Have you tried deleting derived data for your project and rebuilding? (Oh and restart Xcode for good measure!) – mattjgalloway Jan 12 '12 at 09:32
  • For the record, Objective-C doesn't have static methods. The analog of a static method in Objective-C is a C function. Class methods are dynamically dispatched, not statically bound. – jlehr Jan 12 '12 at 15:24

2 Answers2

0

I think you need to change

[language methodFormatComponents];

to

[[language class] methodFormatComponents];

Still, though, @Ben S's point is good. It probably doesn't make sense for all your methods to be class level and should likely be changed to instance methods.

Sean
  • 5,810
  • 2
  • 33
  • 41
0

No freaking way >:|

I just copied the contents of that protocol file, deleted it from my project, recreated it, pasted everything back in and it works. XCode, you will rue the day!!!!

My thanks to everyone who helped me out with this wild goose chase. I'm sorry the result was so unsatisfying :(

Plastech
  • 757
  • 6
  • 17