This might seem as a basic question..but I'm confused regarding how to achieve this with the new swift syntax. On the click of a button on the collection view I'm having something like this....
let productObject = productData1[(indexPath?.row)!]
self.myArray.append(productObject)
Now when I click on that button again I want to check if myArray
has the productObject
already so that it will not be added to the array again...Hope somebody can help...
EDIT: productData1 is a type of struct Product like so...
struct Product {
let name : String
let id : String
var images = [ProductImage]()
var theRate : String
var quantity: String
var sku: String
var prdCateg: String
var prodDescr: String
var mrp: String
var prodcutImage: ProductImage?
init(name : String, id: String, theRate: String, quantity: String, sku: String, prdCateg:String, prodDescr: String, prodcutImage: ProductImage?, mrp: String) {
self.name = name
self.id = id
self.theRate = theRate
self.quantity = quantity
self.sku = sku
self.prdCateg = prdCateg
self.prodDescr = prodDescr
self.prodcutImage = prodcutImage
self.mrp = mrp
}
mutating func add(image: ProductImage) {
images.append(image)
}
}