我无法编译我的 iPhone 项目。在我的 CType.h
中,我收到错误:
Cannot find interface declaration for 'NSObject', superclass of 'CType'.
这会导致许多其他错误,这些错误也在同一个头文件中。
我读到这可能是由于我的项目中的循环引用造成的。因此,我尝试将许多 header 导入更改为转发声明。还有一些我还没有成功地进行前向声明(例如,如果该类继承自另一个类,那么它需要导入,并且如果我正在使用委托(delegate)。不过,可能有一种解决方法)。
我已经多次搜索我的项目,但没有找到循环引用。有什么技巧或窍门可以找到循环引用吗?我认为这可能与我的 CType
有关,但似乎并非如此。
编辑:
这是我的 CType:
界面:
#import <Foundation/Foundation.h>
@interface CType : NSObject
/*
* Type ID
*/
@property (nonatomic, assign) NSInteger typeId;
/*
* Type
*/
@property (nonatomic, strong) NSString *type;
/*
* Initialize with type ID and type
*/
- (id)initWithId:(NSInteger)typeId type:(NSString *)type;
/*
* Type with type ID and type
*/
+ (CType *)typeWithId:(NSInteger)typeId type:(NSString *)type;
@end
实现:
#import "CType.h"
@implementation CType
/* Create setters and getters */
@synthesize typeId;
@synthesize type;
/* Initialize with type ID and type */
- (id)initWithId:(NSInteger)_typeId type:(NSString *)_type
{
if (self = [super init])
{
self.typeId = _typeId;
self.type = _type;
}
return self;
}
/* Type with type ID and type */
+ (CType *)typeWithId:(NSInteger)typeId type:(NSString *)type
{
return [[CType alloc] initWithId:typeId type:type];
}
@end
最佳答案
我倾向于同意@Hot Licks。这很可能是文件损坏或配置错误,因为理论上您的代码没有任何问题。
这是我的建议:
创建一个新类(命名为 CType 以外的名称)并将代码从 CType 迁移到新类。然后删除旧的 CType 文件。如果此时一切正常,则将新类重命名为 CType 并看看会发生什么。另外,请仔细检查您的应用程序 prefix.pch 文件以查看其中导入了哪些 header 。
关于iphone - 寻找循环引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10379822/