I have a class that collects Types into an array, then decides whether an object is of one of the types:
struct Item: Hashable {}
class TypeChecker {
let typeCollection: [Any.Type] = [Item.self]
func acceptObject(_ object: Any) -> Bool {
typeCollection.contains(where: { type(of: object) == $0 })
}
}
let checker = TypeChecker()
let object1: Item = Item()
checker.acceptObject(object1) // returns true
let object2: AnyHashable = Item()
checker.acceptObject(object2) // returns false
In the simplified snipped above, explicitly typed object1 works correctly, however, abstractly typed object2 fails. What gives? How would I fix the TypeChecker?