views:

21

answers:

1

Hi there,

I've created a static getter-function:

@implementation MyClass

static int aValue = 1;
+ (int) aValue { return aValue; }

// other stuff here

@end

and now I'm trying to access it in some different ways from another class:

@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

As you can see the parser seems to have problems with static methods in nested boolean expressions, which is quite unfortunate, if you want to use &&, || and similar clauses.

The full Xcode error message is "Expected ')' before the '.' token". Can someone explain the parser behaviour to me? Am I missing something important or is this a bug?

Le Torbi

+1  A: 

Properties, declared with the @property keyword, only have a meaning in instances.
There's no such thing as a class property.

You can create a getter method, but you won't be able to use the dotted syntax with a class.
Always use the method call: [ MyClass myValue ]

Macmade
Hm yes, I'm aware that Objective-C has no concept for class-properties. However, class-getters and -setters like the ones above are working fine with the dot-syntax, except for nested calls, but shouldn't the dot-syntax be disabled for class-methods in general? IMHO the parser is a bit inaccurate here...BTW: Thx for the fast answer. I'll use method-calls from now on.
Le Torbi
At the C level, a Class is nothing more than a structure. So the dot syntax has a meaning, but certainly not the one you want...
Macmade