I am trying to write an extension of the Swift Array, but I am getting some wierd errors as I try to compile.
My code:
extension Array
{
func itemExists<T: Equatable>(item: T) -> Bool
{
for elt in self
{
if elt == item
{
return true
}
}
return false
}
}
Error:
Cannot invoke '==' with an argument list of type '(T, T)'
Why am I getting this? I am using the Equatable
protocol?
What I also tried was:
extension Array
{
func itemExists<T: Equatable>(item: T) -> Bool
{
var array:[T] = self
for elt in array
{
if elt == item
{
return true
}
}
return false
}
}
Where I got a funny error:
'T' is not identical to 'T'
What am I missing? I read the Apple Documentation about it but I am already using the Equatable
protocol to be able to use the ==
operator on 'T'
.