Reputation: 26223
This came up in another question (kindly answered by meronix) but I curious to learn a little more about what is going on here, is this a LLVM/Clang issue, or are the two statements different in someway.
I know I can fix this by adding (See below), so more curious than anything ...
Upvotes: 0
Views: 792
Reputation: 43472
The two statements are different. A property can only be used if the type of the lvalue declares the property. This is because the getter and setter for the property might be non-obvious (often the case with boolean properties, where the getter is explicitly set to isSomething
.) The compiler cannot infer that without strong type info.
The [lvalue message]
syntax, however, has no such ambiguity, so the compiler allows it. Since the type of the lvalue is id
, any known message can be sent to it without a compiler warning. The compiler will only warn if two signatures correspond to the same selector (for instance, one class has - (UIWindow *)window
and another has - (int)window
.)
The UIApplicationDelegate
protocol defines a window
property, so when you explicitly type your object as id <UIApplicationDelegate>
, the compiler knows about the property and can use it.
Upvotes: 6