1

次のコードはエラーNo visible @interface for 'Bar' declare the selector 'barMethod' on the second line of implementation を生成し-[Foo fooMethod]ます:

//  FooBar.m

#import "FooBar.h"

//////////////////////////////////

@implementation Foo

- (void)fooMethod {
    Bar *bar = [Bar new];
    [bar barMethod]; // Error: No visible @interface for 'Bar' declares the selector 'barMethod'
}

@end

//////////////////////////////////

@interface Bar ()
- (void)barMethod;
@end

@implementation Bar

- (void)barMethod {
    // do something
}

@end

クラス拡張を実装の上-[Bar barMethod]に移動する以外に、FooBar.m 内で宣言を転送する方法はありますか(これはあまり便利ではありません)。BarFoo

4

1 に答える 1