swift - Why Are My Default Property Values Still Showing as Parameters in Init()? -


i have protocol describes marine water parameter needs tested:

protocol parameter {      var name: string { }     var unit: unit { }     var value: double { }  } 

i have struct, calcium, conforms parameter:

struct calcium: parameter {      var name: string = "calcium"     var unit: unit = unitdispersion.partspermillion     var value: double  } 

since name , unit parameters of calcium have default values, why need provide them in init method? shouldn't need provide value value?

i trying understand protocol-oriented-programming , appreciate little guidance here.

enter image description here

  1. this has nothing whatever protocols.

  2. you not have provide initializer value. have not provided any initializer. therefore initializer have 1 provided automatically, , initializer memberwise initializer wants parameters properties.

if don't that, write initializer yourself:

struct calcium: parameter {     var name: string = "calcium"     var unit: unit = unitdispersion.partspermillion     var value: double     init(value:double) {self.value = value} } 

now legal say:

let c = calcium(value:2) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -