class Actor {
let agent: String? = "nobody"
init(agent: String){
self.agent = agent // error: immutable value 'self.agent' may only be initialized once
}
}
let John = Actor(agent: "xyz")
I'm confused about the sequence that is happening here (I'm fully aware of the differences between var
and let
). But why do I get that error?
- If I'm using the
init
method, then doesn't that mean I'm not using the default parameter? - Why can't I change the default constant with another one?