Question

This question is mostly curiosity than anything else. But I currently place all my private methods first in my @implementation so that I can avoid creating an a separate category in my .m file for those methods. As long as the private method was implemented before any other method called it, all was good. I can distinctly remember Xcode warning me if I tried to call a non-declared method before its implementation....at least, I think I can. Now I'm starting to doubt my sanity a little cause Xcode now seems perfectly happy to allow me to call any non-declared method as long as its implementation is located anywhere within the @implementation, even if the call comes before the implementation.

Is this a recent change or have I been structuring my method order off of some archaic 'C' limitation?

The way Xcode is behaving now, it seems there's no need to create any kind of category for private methods. Personally, I find this quite nice.

EDIT: I'm using Xcode 4.3.1

Was it helpful?

Solution

Apparently you are right. xcode 4.2.1 issues a warning and 4.3.1 does not.

@implementation MyClass


- (void) callMyPrivateMethod {
    [self myPrivateMethod];   //<--- xcode 4.2.1 issues a warning here. 
    return;
}

- (void) myPrivateMethod {
    return; 
}

@end

(I know there is no need for the 'return's but I am a bit old fasioned with this respect.)

However, both versions will build it properly and it will runn unless you made a typo in the method name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top