On Nov 25, 2015, at 00:34 , Rick Mann <rm...@latencyzero.com> wrote:
> 
> It seems rather lame that a Swift instance method can't access a static 
> member without prefixing it with the class. Why is this? This is something 
> C++ and Java do just fine.

In a technical sense, the reason is probably that Swift allows class/static and 
instance members to have the same name, presumably because it has to support 
Obj-C methods, where the same thing can happen. That means there’s a danger of 
ambiguity, and it was probably decided that the clunkier disambiguation would 
lead to fewer programmer errors.

Pragmatically, I agree it’s lame. It makes references to static member 
incredibly long, and I hate when my lines wrap. :(

I suppose, if it drives you crazy, you can write an instance method with the 
same name, which invokes the static method. If you mark it with the ‘final’ 
attribute, the compiler should inline it, causing no overhead.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to