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
Post a Comment