To test if object is an instance of class a:
[yourObject isKindOfClass:[a class]]
// Returns a Boolean value that indicates whether the receiver is an instance of
// given class or an instance of any class that inherits from that class.
or
[yourObject isMemberOfClass:[a class]]
// Returns a Boolean value that indicates whether the receiver is an instance of a
// given class.
To get object's class name you can use NSStringFromClass
function:
NSString *className = NSStringFromClass([yourObject class]);
or c-function from objective-c runtime api:
#import <objc/runtime.h>
/* ... */
const char* className = class_getName([yourObject class]);
NSLog(@"yourObject is a: %s", className);
EDIT: In Swift
if touch.view is UIPickerView {
// touch.view is of type UIPickerView
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…