Let's say I have the following class in Swift (which has obvious problems)
class MyClass {
let myProperty: String
init() {
super.init()
self.setupMyProperty()
}
func setupMyProperty() {
myProperty = "x"
}
}
This is overly simplified but I'm basically trying to delegate the initialization of myProperty
into the setupMyProperty()
method. It's a pattern I use often to break down the different parts of the setup of a class.
But of course, I can't call self
until the super initializer has run, and I can't run the super initializer until all the properties have been set, so I'm in a catch 22. On top of it since setupMyProperty()
isn't considered an initializer, it won't be able to assign myProperty
anyway.
Can anyone tell me how to implement this pattern in Swift?