!==
checks for "identity", not "equality". Identity is a property of reference types which all support the AnyObject
protocol, and it means that the two variables that you are comparing point to the same actual object, and not just another object with the same value.
That means you can't use ===
or !==
with normal value types, like strings, integers, arrays, etc.
Try typing this into a playground:
let a = "yes"
let b = a
println(a === b)
You should get a message saying that String
doesn't conform to the AnyObject
protocol, because String is a value type (a struct) and doesn't support AnyObject
, so you can't use ===
with it.
You can use ===
with any instance of a class, because classes are reference types, not value types.
You could put a constraint on T requiring that it conform to AnyObject
.
func removeObject<T : Equatable where T: AnyObject>...
It should work, then, for reference types (including all class instances). But then your function won't work for value types (which include all structs).
Why do you need to check for identity (===
) instead of equality (==
)?