Swift provides the is keyword (and as?) to check whether an object can be downcast successfully:
is
as?
if foo is MyClass { // ... }
But NSObjectProtocol also provides the original func isKindOfClass(aClass: AnyClass!) -> Bool:
NSObjectProtocol
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.
isKindOfClass()
NSObject
1.4m articles
1.4m replys
5 comments
57.0k users