我创建了一个静态getter函数:
@implementation MyClass
static int aValue = 1;
+ (int) aValue { return aValue; }
// other stuff here
@end
现在我试图以不同的方式从另一个类访问它:
@implementation AnotherClass
- (void) aMethod {
if (MyClass.aValue > 0) { NSLog(@"Foobar"); } // No parser error
if ((MyClass.aValue > 0)) { NSLog(@"Foobar"); } // My parser doesn't like that
if (([MyClass aValue] > 0)) { NSLog(@"Foobar"); } // This is ok again
if ((0|MyClass.aValue > 0)) { NSLog(@"Foobar"); } // Gives a warning, but works
}
// other stuff here
@end
正如您所看到的,解析器在嵌套的布尔表达式中似乎存在静态方法的问题,这非常不幸,如果您想使用&&,||和类似的条款。
在“。”之前,完整的Xcode错误消息是“预期的”)。令牌”。有人可以向我解释解析器的行为吗?我错过了一些重要的东西或者这是一个错误吗?
Le Torbi
答案 0 :(得分:1)
使用@property关键字声明的属性仅在实例中具有含义 没有类属性。
您可以创建一个getter方法,但是您无法在类中使用带点的语法
始终使用方法调用:[ MyClass myValue ]