I'm using Swift 1.2, and I'm having a hard time understanding why this extension does not compile. I must be missing something - T is Equatable and therefore I thought I should be able to compare via the '==' operator?
extension Array {
func indexOf<T:Equatable>(element: T?) -> Int?
{
if element != nil {
for (var i = 0; i < self.count; i++)
{
var val = self[i]
if val == element! { // Error: Binary operator '==' cannot be applied to two T operands
return i
}
}
}
return nil
}
}