initialization - Init a class with arguments on swift -


this question has answer here:

i trying init class arguments in swift. want able pass array class. let test = mytestclass(data).

code:

init(data: [cgfloat]){     super.init(nibname: "test", bundle: nil)     self.data = data }  required init?(coder decoder: nscoder) {      super.init(nibname: "test", bundle: nil) } 

error:

enter image description here

you can solve errors initializing data before calling super in init(coder , call appropriate super method in init(coder

let data : [cgfloat]  init(data: [cgfloat]){     self.data = data     super.init(nibname: "test", bundle: nil) }  required init?(coder decoder: nscoder) {     self.data = [cgfloat]()     super.init(coder: decoder) } 

alternatively declare data

var data = [cgfloat]() 

then can write

init(data: [cgfloat]){     self.data = data     super.init(nibname: "test", bundle: nil) }  required init?(coder decoder: nscoder) {     super.init(coder: decoder) } 

in case have call super.init(coder: decoder) in init(coder.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -