How do I declare a class level function in Swift?

后端 未结 5 418
借酒劲吻你
借酒劲吻你 2020-12-23 09:09

I can\'t seem to find it in the docs, and I\'m wondering if it exists in native Swift. For example, I can call a class level function on an NSTimer like so:

5条回答
  •  甜味超标
    2020-12-23 09:51

    UPDATED: Thanks to @Logan

    With Xcode 6 beta 5 you should use static keyword for structs and class keyword for classes:

    class Foo {
        class func Bar() -> String {
            return "Bar"
        }
    }
    
    struct Foo2 {
        static func Bar2() -> String {
            return "Bar2"
        }
    }
    

提交回复
热议问题