gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 18:42:01 40 4
gpt4 key购买 nike

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

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

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

@interface MyViewController : UIViewController <UITextFieldDelegate, UIAlertViewDelegate> {
...
}

我想像这样使用我的 AppDelegate:

MyAppDelegate* appDelegate = (MyAppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate doSomething];

但是,一旦我#import“MyAppDelegate.h”,编译器就会抛出很多(不相关的)错误,比如

Cannot find interface declaration for 'MyOtherViewController', superclass of 'MyOtherViewController2' 

问题是:我可以在其他 header 中很好地包含我的 AppDelegate。我无法弄清楚可能有什么区别。请帮我弄清楚是什么原因造成的!非常感谢!

PS:GCC 和新的 LLVM 都会发生这种情况。

最佳答案

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

关于objective-c - iOS:当我将 AppDelegate.h 包含到另一个头文件中时,什么会导致 Xcode 编译器抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9976710/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com