【发布时间】:2015-03-20 01:04:43
【问题描述】:
以下代码产生错误No visible @interface for 'Bar' 在-[Foo fooMethod] 的第二行实现中声明选择器'barMethod':
// 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 类扩展移到Foo 实现之上(有时不是很方便)之外,还有什么方法可以在FooBar.m 中转发声明-[Bar barMethod]?
【问题讨论】:
-
@JoshCaswell 不错的解决方法,但更改顺序更容易
标签: objective-c class-extensions