iOS:当我将AppDelegate.h包含到另一个头文件中时,什么可能导致Xcode编译器抛出错误?

cit*_*cit 0 compiler-construction import objective-c ios

我正在尝试#import我的"AppDelegate.h"到同一项目的另一个头文件中,以便访问我的iOS项目的AppDelegate的方法.

所以,我的头文件看起来像这样:#import

#import "DataProvider.h"
#import "MyAppDelegate.h"

@interface MyViewController : UIViewController <UITextFieldDelegate, UIAlertViewDelegate> {
...
}
Run Code Online (Sandbox Code Playgroud)

我想像我这样使用我的AppDelegate:

MyAppDelegate* appDelegate = (MyAppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate doSomething];
Run Code Online (Sandbox Code Playgroud)

但是,只要我#import"MyAppDelegate.h",编译器就会抛出很多(无关的)错误,比如

Cannot find interface declaration for 'MyOtherViewController', superclass of 'MyOtherViewController2' 
Run Code Online (Sandbox Code Playgroud)

问题是:我可以在其他标题中包含我的AppDelegate.我无法弄清楚可能存在的差异.请帮我弄清楚是什么原因引起的!非常感谢!

PS:这种情况发生在GCC以及新的LLVM上.

Phi*_*lls 5

将#import移动到.m文件中.如果您需要.h中的MyAppDelegate符号,请@class MyAppDelegate;改用.