これは、クラス実装自体の外部で使用されないメソッドを宣言するための完全に合法的な方法です。
コンパイラは、メソッドが使用されているメソッドの前にある限り、実装ファイル内のメソッドを検索します。ただし、新しい LLVM コンパイラでは、メソッドを任意の順序で宣言し、特定のファイルから参照できるため、常にそうとは限りません。
実装ファイル内でメソッドを宣言するには、いくつかの異なるスタイルがあります。
//In the Header File, MyClass.h
@interface MyClass : NSObject
@end
//in the implementation file, MyClass.m
//Method Decls inside a Private Category
@interface MyClass (_Private)
- (void)doSomething;
@end
//As a class extension (new to LLVM compiler)
@interface MyClass ()
- (void)doSomething;
@end
@implementation MyClass
//You can also simply implement a method with no formal "forward" declaration
//in this case you must declare the method before you use it, unless you're using the
//latest LLVM Compiler (See the WWDC Session on Modern Objective C)
- (void)doSomething {
}
- (void)foo {
[self doSomething];
}
@end