class Animal {} class Cat: Animal {} class Robot {} func isSubclass<T>(_ object: Any, of: T.Type) -> Bool { return object is T && !(type(of: object) == T.self) } isSubclass(Cat(), of: Animal.self) isSubclass(Animal(), of: Animal.self) isSubclass(Robot(), of: Animal.self)