你可以在 Xcode 附带的 cocoa 和 Objective-c 手册中找到答案。
#import <Foundation/Foundation.h>
void printIntrospectionInfo()
{
NSMutableArray * array = [NSMutableArray arrayWithCapacity:5];
[array addObject: [NSString stringWithString:@"Example NSString object"]];
[array addObject: [NSMutableString stringWithString:@"Example NSMutableString object"]];
[array addObject: [NSURL URLWithString:@"http://apple.com.au"]];
[array addObject: [NSProcessInfo processInfo]];
[array addObject: [NSDictionary dictionaryWithObject: @"DictObject" forKey: @"KeyObject"]];
[array addObject: [NSNumber numberWithInt:123456]];
SEL sel_lowercase = @selector(lowercaseString);
int i;
for (i = 0; i < [array count]; ++i)
{
id o = [array objectAtIndex:i];
NSLog(@"%@", o);
NSLog(@"Class name: %@", [[o class] className]);
NSLog(@"Is Member of NSString: %@", ([o isMemberOfClass: [NSString class]] ? @"YES" : @"NO"));
NSLog(@"Is Kind of NSString: %@", ([o isKindOfClass: [NSString class]] ? @"YES" : @"NO"));
NSLog(@"Responds to lowercaseString: %@", ([o respondsToSelector: sel_lowercase] ? @"YES" : @"NO"));
if ([o respondsToSelector: sel_lowercase])
NSLog(@"lowercaseString: %@", [o performSelector: sel_lowercase]);
NSLog(@"===================");
}
}
int main(int argc, const char* argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
printIntrospectionInfo();
[pool release];
return 0;
}