为什么子类@property没有相应的ivar隐藏超类ivars?

Cri*_*ris 12 objective-c ios4 ios

以下似乎很简单.有一个带有ivar的超类,以及一个访问(@protected)超类ivar的子类:

// Testclass.h    
@interface TestClass : NSObject {
    NSString *testIvar;
}
@end

//TestClass.m
@implementation TestClass
@end

//TestSubclass.h
@interface TestSubClass : TestClass {
}

@property (nonatomic, retain) NSString *testProperty;
- (void) testMethod;

@end

//TestSubclass.m    
#import "TestSubClass.h"
@implementation TestSubClass

@synthesize testProperty;

- (void) testMethod{
    NSLog(@"The value was: %@", testIvar);
}
@end
Run Code Online (Sandbox Code Playgroud)

简单而正确 - 看似足够.但是,尝试编译(对于iOS 4.2 SDK,使用GCC 4.2)会产生指向NSLog行的错误:'testIvar unclared'.

我是Objective-C的新手,但不能为我的生活看到为什么这应该是一个错误.注释掉testProperty的东西,它编译好了.似乎在没有相应的ivar的子类中添加合成属性实际上隐藏了一个不相关的超类ivar.

任何人都可以告诉我这里发生了什么?相关的,编译错误是否可以预见?(预见它可以节省我一些时间和挫折).

zou*_*oul 7

LLVM无需投诉即编译源代码,切换到LLVM:选择目标→获取信息→构建→C/C++编译器版本→LLVM 1.5.从我有限的经验来看,无论如何它都是一个更好的编译器.不知道为什么海湾合作委员会的行为方式 - 有趣的捕获.