class - Declaring type in array? -


i'd create class instance within array declaration. how done?

something similar following:

myclassa.myarray = [classb() {name="cleaning", deptid=12}, classb() {name="repairs", deptid=30] 

where array type is:

class classb : nsobject {   var name:string?   var deptid:int? } 

your array type classb. have create initializer classb. example:

class classb: nsobject {     var name:string?     var deptid:int?     init(name: string, deptid: int) {         self.name = name         self.deptid = deptid     } }  class classa {     var myarray:[classb] = [] }  let myclassa = classa()  myclassa.myarray = [classb(name: "cleaning", deptid: 12), classb(name: "repairs", deptid: 30)] 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -