Skip to content

Protocol extension should not provide undeclared method implementations #31

@wnagrodzki

Description

@wnagrodzki

It is usually not obvious that static dispatch is going to be used. If object implementing MyProtocol delivers it own numberOfItems implementation it is not going to be called. (add an example to show the problem)

protocol MyProtocol {
    func item(at index: Int) -> String
}

extension MyProtocol {
    var numberOfItems: Int { return 4 }
}

Declare methods added via protocol extension.

protocol MyProtocol {
    var numberOfItems: Int { get }
    func item(at index: Int) -> String
}

extension MyProtocol {
    var numberOfItems: Int { return 4 }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions