以前i posted a question in SO ,不知道是什么原因导致了这个错误。后来我创建了一个新项目并重新创建了错误。这就是它所说的;
我收到一个名为“未知类型名称考试
”的错误。我在不同的标题下发布了一个问题。但现在我发现了问题所在(所以我创建了另一个问题,希望人们不会反对这一举动,并为我的问题提供解决方案:))
我创建了一个新项目来查找问题所在。
我创建了一个名为 Exam
的 NSObject
类。
在 AppDelegate.h 中我添加了以下内容;
#import <UIKit/UIKit.h>
#import "Exam.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>{
Exam *ex;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) Exam *ex;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end
在 AppDelegate.m 中,我只有综合 ex
,所以我不会在此处粘贴该代码。
现在在考试类(NSObject类)中,我有以下代码;
#import "AppDelegate.h"
#import <Foundation/Foundation.h>
@interface Exam : NSObject {
AppDelegate*APP; <-- here i get Unknown type AppDelegate.
}
@end
一旦我在此处创建 AppDelegate
对象,我就会收到错误。
注意:我正在使用 ARC
最佳答案
将Exam.h更改为
#import <Foundation/Foundation.h>
@class AppDelegate
@interface Exam : NSObject {
AppDelegate*APP; <-- here i get Unknown type AppDelegate.
}
@end
然后你的Exam.m上面的@implementation
执行此操作
#import "AppDelegate.h"
// Rest is same
@implementation ...
当前您正在 Appdelgate.h 中导入 Exam.h,在 Exam.h 中导入 AppDelegate.h ..这使得这两个类在执行自身之前相互导入..这会导致编译器错误..因为每个类都引用另一个类..
关于iphone - 未知类型考试和未知类型 AppDelegate 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9656504/