I have a custom class Product defined as
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 an array with that custom class
let toy = [
Product(name: "Car", priceLabel: "$5.00"),
Product(name: "Train", priceLabel: "$2.50")
]
How would I insert the UIImage into that array? I would need to insert a different picture for each toy.
Thanks in advance
There are a few way to do it but with your code just example 1 will work:
You have just one init which takes 3 parameters so if you create object like that:
it won't compile because you have not initialiser which accept just two parameters.