Im learning swift currently. While learning I'm stuck with generics. Im solving one simple problem that -> return index of specified element in an array
import UIKit
extension Array
{
func indexOfLetter<T:Equatable>(item:T) -> Int
{
var i = 0
for (index, value) in enumerate(self)
{
if value == item
{
return i
}
i++
}
return -1;
}
}
var arrayOfItems = ["A","B"]
arrayOfItems.indexOfLetter("A")
in this code I'm getting error that we
Can not compare two operands using == operator which are of type T.