Abdou023 Abdou023 - 4 months ago 10x
Swift Question

Remove elemnt of custom class from an array

I have an array of objects of custom class

which doesn't subclass anything, and I want to remove an element from it:

var components: [Component] = [comp1, comp2, comp3]

components = components.filter({$0 != comp2}) // Error

the error:

Binary operator '!=' cannot be applied to two 'Component' operands


Use !== instead which returns true if two objects do not refer to the same instance.