I have a protocol called SomeProtocol
I want to create a function that get an object that confirms to this protocol, and add it to an array.
then I have another function that remove an object from this array.
var allObjs = [SomeProtocol]()
func addObj<T: AnyObject where T: SomeProtocol>(obj: T) {
allObjs.append(obj)
}
func removeObj<T: AnyObject where T: SomeProtocol>(obj: T) {
for someObj in allObjs {
if someObj == obj { // compile time error -> Binary operator '==' cannot be applied to operands of type 'SomeProtocol' and 'T'
}
}
}
This code will cause a compile time error "Binary operator '==' cannot be applied to operands of type 'SomeProtocol' and 'T'"
not sure how can i fix that, both object where defined as AnyObject who confirm to the SomeProtocol protocol, so what is the problem here?