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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With