swift - Ambiguous func in two protocols -
i think might rare situation, how can deal same (ambiguous) function 2 different protocol. example, have these defines:
protocol { func foo() func bar() -> int } protocol b { func foo() func bar() -> string }
now have class conforms , b. can implement different versions of foo()
, b separately. if can so, how can call them?
p.s. know bar()
, can use make call:
let anint = (instance a).bar() let astring = (instance b).bar()
is possible similar thing on foo()
function?
no. point of protocol requires object provide particular method, method not "tied" protocol. that's why can use extensions cause existing classes conform new protocols using existing methods.
as note, sounds mistake in protocol design. having 2 protocols require different semantics same method name suggests method incorrectly named.
Comments
Post a Comment