The initialization process has a few constraints on what can be done within an init
function.
From StackOverflow
You can't call methods on self before all non-optional instance variables are initialized. There are several ways to go around that.
- Change properties to optionals or implicitly unwrapped optionals (not recommended)
- Make the methods static.
- Make the methods as a
fileprivate
function in the file. - You just have to avoid calls to self before the class is initialized.