Reputation: 12227
The compiler seems to be happy, I'm happy with slightly improved readability, but Xcode's code completion doesn't particularly recognize alloc
and class
when invoked this way:
MyClass* object = [MyClass.alloc initWithBounty:bounty];
<...>
if ([object isKindOfClass:MyClass.class])
<...>
So I was wondering what is wrong with the above, if at all?
Upvotes: 0
Views: 79
Reputation: 237080
Well, primarily what's wrong is that dot notation is for retrieving things that are conceptually properties. alloc
does not access a property of the class; it creates an object. Using it for any zero-argument method is not more readable — it's confusing.
MyClass.class
is actually not problematic in that way, but there's no way to declare properties on a class and they usually aren't thought of as having properties, so the autocomplete apparently doesn't support it.
Upvotes: 3
Reputation: 86065
Dot notation is originally added to be used for property access. So you can use them only for
Otherwise, recent compiler will complain about it.
Anyway, I agree to @nhgrif that using dot notation on non-property method is not a good practice.
Upvotes: 1