Created
September 22, 2017 22:52
-
-
Save ygweric/325fdffc4d34091e58fd364ac7bdcbbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
func isExactClass<T>(obj: Any, _ _: T.Type) -> Bool{ | |
return type(of: obj) == T.self | |
} | |
class Dog { | |
} | |
class Wolf: Dog { | |
} | |
let dog = Dog() | |
let wolf = Wolf() | |
wolf.self === Dog.self //false | |
dog.self === Dog.self //false | |
type(of: dog) == Dog.self //true | |
type(of: wolf) == Dog.self //false | |
isExactClass(obj: dog, Dog.self) //true | |
isExactClass(obj: wolf, Dog.self) //false | |
var x: Any.Type | |
x = Dog.self | |
type(of: dog) == x // true | |
type(of: x) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment