This is one of those annoying little quirks that you can waste time trying to track down…
I was recently developing a straight forward class and I was trying to reference a method I had declared in the header file within the implementation of another method in the class. I kept getting the common error message:
No visibible @interface for 'SomeClass' declares the selector 'someMethod'
I checked the header file and the definition was there just I expected, with no errors flagged against it:
- (void):someMethod:(NSString *)something;
At this point you may well see the glaring error and have jumped to the conclussion that I am an idiot. Of course I was stuck in the age old debugging/proof reading issue of seeing what I expected to see, not what I had actually written.
I spent 10 minutes going through the traditional "What's wrong with that? There it is! What's the problem? Stupid compiler." internal dialog.
I read through the rest of the .h file to see if there was some error before it that was throwing the compiler. I tried renaming the method in case I had hit on a reserved word. I tried modifying a similarly named property in case it was causing confusion. I tried moving it around within the .h, and other useless measures.
Being aware of the problem of being blind to obvious errors, I ended up typing the declaration again without copying the original. Nine keystrokes later I saw the issue, the random ':' before the selector name!
Ah the joy of being a coder. This sort of thing always makes me feel stupid for three reasons:
- Making the mistake in the first place,
- Failing to see it even after rereading the line of code multiple times, and
- The increasingly desparate and bizzare theories I come up with to try to explain/rectify it.
The thing that puzzles me is why the compiler didn't flag this as an error in the .h file. I can't see how this could be parsed as a well formed selector declaration. If anybody has any suggestions I would be really interested.