I try to use generic method in order to find the index of the item in the array
public extension Array where Element: AnyObject {
func findIdxOf<T: AnyObject>(_ item: T) -> Int? {
return self.firstIndex{ $0 === item }
}
}
Usage:
struct FeedData: Codable {
...
}
var currentFeedsArr: [FeedData] = []
var feed = FeedData()
let idx: Int? = currentFeedsArr.findIdxOf(feed)
Error that I get -
Instance method 'findIdxOf' requires that 'FeedData' be a class type
Referencing instance method 'findIdxOf' on 'Array' requires that 'FeedData' be a class type
How to solve it?