Abdou023 Abdou023 - 1 year ago 91
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download