Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between "is" and isKindOfClass()?

Tags:

swift

Swift provides the is keyword (and as?) to check whether an object can be downcast successfully:

if foo is MyClass {     // ... } 

But NSObjectProtocol also provides the original func isKindOfClass(aClass: AnyClass!) -> Bool:

if something.isKindOfClass(MyClass) {     // ... } 

For classes conforming to NSObjectProtocol, is this really much different?

like image 223
jtbandes Avatar asked Jul 22 '14 01:07

jtbandes


1 Answers

Yes there is a difference: is works with any class in Swift, whereas isKindOfClass() works only with those classes that are subclasses of NSObject or otherwise implement NSObjectProtocol.

like image 167
2 revs Avatar answered Sep 22 '22 19:09

2 revs