I am trying to get my head around initializers in Swift. I kind of get what they do, but I dont get why I need them.
For example: (from apples documentation)
class NamedShape {
var numberOfSides = 0
var name: String
var sideLength: Double
init(name: String, sideLength: Double) {
self.name = name
self.sideLenght = sideLength
}
}
If init should set an initial value, shouldn't self.sideLength
equals an actual value, instead of just "sideLength". Or do I need to create an init to take in arguments to a function?
I'm so confused but would really appreciate if someone could help me.