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: email@hidden
- Date: Wed, 25 Nov 2015 19:40:13 +0900
In the Objective-C case class methods are methods of the class object.
Perhaps your object descends from NSObject?
Sent from my iPhone
> On Nov 25, 2015, at 6:04 PM, Quincey Morris <email@hidden> wrote:
>
>> 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
_______________________________________________
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