[swift-users] Why is static a keyword?

Jose Cheyo Jimenez cheyo at masters3d.com
Thu May 11 12:22:10 CDT 2017


I can understand class being a keyword because you use the same word to declare an object. So `class` is used in different contexts like you showed below. That is not the case for static. Class can appear at the top level but IFAIK static will not appear at top level declarations. 

> On May 11, 2017, at 9:59 AM, Zhao Xin <owenzx at gmail.com> wrote:
> 
> In Swift, you use `static in struct and enum` and `class in class`. For example,
> 
> struct Foo {
>     static func bar() {
>         
>     }
> }
> 
> class ClassFoo {
>     class func bar() {
>         
>     }
> }
> 
> Another the `class func bar()` can replace to `static` as well. Here the `static` and `class` are equal in functions of classes.
> 
> And `class` is a keyword.
> 
> class ClassFoo2 {
>     static func bar() {
>         
>     }
> }

static func bar() = final class func bar() 
But if you type final class the compiler will say to make it static instead. 

static func bar() != class func bar()

Static is only an attribute modifier. Class is a modifier and a declaration depending on context.  Why must static be a keyword when every other modifier is not? 

> 
> Zhaoxin
> 
> 
>> On Fri, May 12, 2017 at 12:17 AM, Jose Cheyo Jimenez via swift-users <swift-users at swift.org> wrote:
>> I was expecting static to be a builtin. Does anybody know why it must be a keyword? 
>> 
>> Background. https://bugs.swift.org/browse/SR-4834
>> 
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170511/8b3fbccb/attachment.html>


More information about the swift-users mailing list