0

I have extended the following protocol with a default parameter.

protocol XDelegate {
    func close(response: Bool, status: Status)
}

extension XDelegate{
    func close(response: Bool, status: Status = .UNDEFINED){}
}

whenever I call delegate.close(true) it won't EVER call the function on the class that adopted this protocol.

I MUST do delegate.close(true, status: .UNDEFINED) so it would call the function.

Is this the expected behavior?

I'm using Swift 2.3

EDIT: See the duplicate link and also see this answer and the comments below it.

mfaani
  • 33,269
  • 19
  • 164
  • 293
  • 1
    This looks quite similar https://stackoverflow.com/questions/42634816/implementing-a-function-with-a-default-parameter-defined-in-a-protocol – duplicate? – Martin R Sep 21 '17 at 18:52
  • Also: https://stackoverflow.com/questions/34601931/is-it-possible-to-satisfy-swift-protocol-and-add-defaulted-arguments – dan Sep 21 '17 at 18:53
  • Your default parameter version in the extension should call the other one in its implementation – dan Sep 21 '17 at 18:54
  • 1
    Most probably unrelated to the issue, but why use Swift 2.3 when Swift 4 is being released soon and Swift 3 has been out for quite a while now? – Dávid Pásztor Sep 21 '17 at 21:26
  • @DávidPásztor Long story short. Not my decision! – mfaani Sep 22 '17 at 13:43

0 Answers0