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.
this has nothing whatever protocols.
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
Post a Comment