2

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

Aaron Hayman
  • 8,492
  • 2
  • 36
  • 63
  • duplicate of [Private Method Declaration Objective-C](http://stackoverflow.com/questions/9414410/private-method-declaration-objective-c) – jscs Mar 10 '12 at 18:56

1 Answers1

1

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.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71
  • Thanks for the confirmation. I was pretty sure it wasn't there in earlier builds of Xcode but it's nice to have confirmation. It's also a really nice addition. – Aaron Hayman Mar 10 '12 at 19:37