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 -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -