我的 .pch 文件中有这个:
#import "UIViewController+Loader.h"
该类别的实现如下所示:
static char kUIViewControllerBaseViewKey;
@implementation UIViewController (Loader)
- (void)setLoader:(LoaderView *)loaderView {
objc_setAssociatedObject(self, &kUIViewControllerBaseViewKey, loaderView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (LoaderView *)loader {
LoaderView *loaderView = (LoaderView *)objc_getAssociatedObject(self, &kUIViewControllerBaseViewKey);
if (!loaderView) {
loaderView = [[LoaderView alloc] initWithView:self.view];
[self.view addSubview:loaderView];
[self setLoader:loaderView];
}
return loaderView;
}
@end
问题是,当我这样做时,在任何视图控制器中:
[self.loaderView doSomething];
Xcode 显示此错误:Property 'loaderView' not found on object of type MyViewController
但是,该项目编译良好,并且 loaderView 上的 doSomething: 方法工作正常。如何让 Xcode 停止显示这些错误?