The Swift initialization sequence is slightly different from Objective-C,
class BaseClass { var value : String init () { value = "hello" } }
subclass below.
class SubClass : BaseClass { var subVar : String let subInt : Int override init() { subVar = "world" subInt = 2015 super.init() value = "hello world 2015"
Initialization Sequence:
- Initialize a subclass of var or let,
- Call super.init () if the class has a superclass,
- Change the value of the superclass if you want to do this.
I think your code is:
override init() { self = super.init() //just call super.init(), do not assign it to self return self; //it is unnecessary to return self }
We must remember the initialization of all var or let classes.
source share