[Reprinted]isKindOfClass in Swift

Stack Overflow轉載有三種方式,在Swift 4也是不變
Option 1:
if view is UITabBarItem {

}

Option 2:
if view.isKind(of:UITabBarItem.self) {

}

Option 3:
if view.isMember(of:UITabBarItem.self) {

}

The difference between isKind:of and isMember:of is:
●isKind:of returns YES if the receiver is an instance of the exact class, OR if the receiver is an instance of any subclass of the class.
●isMember:of only returns YES if the receiver is an instance of the exact class you're checking against

沒有留言: