Re: Why can't a Swift method directly access a static member?
Re: Why can't a Swift method directly access a static member?
- Subject: Re: Why can't a Swift method directly access a static member?
- From: Quincey Morris <email@hidden>
- Date: Wed, 25 Nov 2015 01:04:18 -0800
- Feedback-id: 167118m:167118agrif8a:167118slcVnw8eKG:SMTPCORP
On Nov 25, 2015, at 00:34 , Rick Mann <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden