Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isMemberOfClass in Swift

Tags:

ios

swift

The keyword is is equivalent to isKindOfClass.

But I am unable to find what is equivalent of isMemberOfClass in swift.

Note: My question is not about the difference between isKindOfClass or isMemberofclass rather the question is about what is the equivalent of isMemberofClass in Swift

somebody please clarify

like image 612
RajuBhai Rocker Avatar asked Sep 06 '16 11:09

RajuBhai Rocker


1 Answers

You are looking for type(of:) (previously .dynamicType in Swift 2).

Example:

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
like image 93
Grimxn Avatar answered Sep 18 '22 07:09

Grimxn