This is more of a concept question. Why bother with using init
?
class Person {
var name:String
var height:Double
...
init(name: String) {
self.name = name
self.height:Double
...
}
Why not just give everything a default value?
var name = "Daniel"
var height = 178.0
That way, I also won't have to worry about deciding between designated and 'convenience' inits because everything would just inherit from their superclass. Is there a reason for having this init
method?
Does it allow for coding patterns that a strictly default-value-initialized app cannot achieve? Or is it for reasons like resource/memory management?