Reputation: 89
Is there a universal way to get the type of class of an object such as:
NSString *classType = [Class kind];
rather than iterating through them like:
if ([object isKindOfClass: [NSNull Class]]) {
//it is null
}
else if ([object isKindOfClass: [NSObject Class]]) {
//it is an object
}
//and so forth
Upvotes: 1
Views: 55
Reputation: 18290
While it is common to use NSStringFromClass(anObj), you should also know about Swift 3's type(of:) function.
import Foundation
class Foo:NSObject {}
let bar = Foo()
let barType = type(of:bar)
print("\(barType)")
Looks like this in playgrounds:
Upvotes: 0