Answers for "swift check if class is of type"

0

swift check if class is of type

class Animal {}
class Dog : Animal {}
class Cat : Animal {}

let c = Cat()

c is Dog // false
c is Cat // true
c is Animal // true

// In Swift => 3:
type(of: c) == Cat.self // true
type(of: c) == Animal.self // false

// In Swift 2:
c.dynamicType == Cat.self // true
c.dynamicType == Animal.self // false
Posted by: Guest on February-08-2022

Code answers related to "swift check if class is of type"

Code answers related to "Swift"

Browse Popular Code Answers by Language