ios - Display UIImage within an array with custom class in Swift -


i have custom class product defined

class product: nsobject {  var name: string var pricelabel: string var productimage: uiimage   init(name: string, pricelabel: string, productimage: uiimage) {     self.name = name     self.pricelabel = pricelabel     self.productimage = productimage     super.init()     } } 

and i've created array custom class

    let toy = [     product(name: "car", pricelabel: "$5.00"),     product(name: "train", pricelabel: "$2.50")     ] 

how insert uiimage array? need insert different picture each toy.

thanks in advance

there few way code example 1 work:

// example 1: let toy = [     product(name: "car", pricelabel: "$5.00", productimage:uiimage(named: "myimage.png")!),     ...     ]  // example 2: let product1 = product(name: "car", pricelabel: "$5.00") product1.productimage = uiimage(named: "myimage.png")! let toy = [         product1,         ...         ]    // example 3: let toy = [         product(name: "car", pricelabel: "$5.00"),         ...         ] if let prod = toy[0] {     prod.productimage = uiimage(named: "myimage.png")! } 

you have 1 init takes 3 parameters if create object that:

product(name: "car", pricelabel: "$5.00") 

it won't compile because have not initialiser accept 2 parameters.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -