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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -