而不是:
[someOtherObject invokeSelector:@selector(someMethod) forClass:[SomeClass class];
电话:
[[SomeClass class] performSelector:@selector(someMethod)];
示例(使用GNUstep…)
存档A.h
#import <Foundation/Foundation.h>
@interface A : NSObject {}
- (NSString *)description;
+ (NSString *)action;
@end
上午归档
#import <Foundation/Foundation.h>
#import "A.h"
@implementation A
- (NSString *)description
{
return [NSString stringWithString: @"A"];
}
+ (NSString *)action
{
return [NSString stringWithString:@"A::action"];
}
@end
其他地方:
A *a = [[A class] performSelector:@selector(action)];
NSLog(@"%@",a);
输出:
2009-11-22 23:32:41.974 abc[3200] A::action
http://www.cocoabuilder.com/archive/cocoa/197631-how-do-classes-respond-to-performselector.html的解释很好:
"在Objective-C中,类对象获取