cfisher cfisher - 11 months ago 53
Swift Question

Static keyword in Swift 3 protocol

I noticed that some functions in

have the
keyword. However, when you implement the function, you must remove the
keyword to make the compiler happy.

public static func <(lhs: Self, rhs: Self) -> Bool

What does
mean in the context and what is its purpose?


From the Xcode 8 beta 4 release notes:

Operators can be defined within types or extensions thereof. For example:

struct Foo: Equatable {
    let value: Int
    static func ==(lhs: Foo, rhs: Foo) -> Bool {
        return lhs.value == rhs.value

Such operators must be declared as static (or, within a class, class final), and have the same signature as their global counterparts. As part of this change, operator requirements declared in protocols must also be explicitly declared static:

protocol Equatable {
    static func ==(lhs: Self, rhs: Self) -> Bool