IOS程序编译报如下错误:、
Loading two versions of Object
这是源代码:
#import <Foundation/Foundation.h>
@interface Object : NSObject
{
id name;
}
- (void) setName: (id) i;
- (id) getName;
- (void) print;
@end //Object
@implementation Object
- (void) setName: (id) i
{
name = i;
}
- (id) getName
{
return name;
}
- (void) print
{
NSLog(@"name=%@",name);
}
@end //Object
int main(int argc, char* argv[])
{
//id s = @"Hello Test";
id o = [Object new];
[o setName: @"Object Test"];
[o print];
return 0;
}
将Object改为KLObject之后就没问题,修改后的源码
#import <Foundation/Foundation.h>
@interface KLObject : NSObject
{
id name;
}
- (void) setName: (id) i;
- (id) getName;
- (void) print;
@end //KLObject
@implementation KLObject
- (void) setName: (id) i
{
name = i;
}
- (id) getName
{
return name;
}
- (void) print
{
NSLog(@"name=%@",name);
}
@end //KLObject
int main(int argc, char* argv[])
{
//id s = @"Hello Test";
id o = [KLObject new];
[o setName: @"KLObject Test"];
[o print];
return 0;
}
运行结果:
目前还没有彻底的搞清楚是什么原因导致的冲突,只不过也提醒了我类名的规范。也算是有助于代码质量的提高吧,呵呵!