struct - Mutating in Structure Swift Same function Name -


still trying out swift, , came across problem (not sure if classifies one)

so have protocol, , structure inherits it.

protocol exampleprotocol {  var simpledescription: string { }  func adjust() }  struct simplestructure : exampleprotocol{    var simpledescription = "a simple structure"     mutating func adjust() {       simpledescription += " (adjusted)"    }     func adjust() { //i created second method conform protocol    } }   var b = simplestructure() b.adjust() //this generates compiler error mentioning ambiguity (correct) 

question how call mutating adjust() not adjust protocol. i.e. know if declare b protocol , initialized struct call adjust protocol, how call first adjust ? or not possible? or using wrongly ?

cheers,

your code doesn't compile, error in redefining adjust method adding mutating attribute - doesn't create overloaded version of adjust.

in opinion correct code:

protocol exampleprotocol {     var simpledescription: string { }     mutating func adjust() }  struct simplestructure : exampleprotocol{     var simpledescription = "a simple structure"      mutating func adjust() {         simpledescription += " (adjusted)"     } } 

which means: have define adjust function mutating in protocol.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -