I have a class Products
class Products { var name:String = "" var number:Int = 0 init(name: String, number: Int) { self.name = name self.number = number } }
Then in the field of view of the controller
var productFirst:[Products] = [Products(name: "First", number: 1)] var productSecond:[Products] = [Products]()
I use productFirst to populate a tableView.
I want to add the selected row to productSecond and it works:
productSecond.append(productFirst[indexPath.row])
But I do not want to duplicate the elements in the array, so I did
if !contains(productSecond, productFirst[indexPath.row]) { productSecond.append(productFirst[indexPath.row]) }
I get an error. How to change it? When productFirst and productSeconds are just arrays of strings, it works fine, but now I need objects.
On the error: firstly, "could not find an overload for"! "which accepts the provided arguments. After removing the exclamation mark, it" cannot call contains a list of arguments of the type "(@lvalue [Products, $ T8) '
source share