我有一个有趣的问题,我试图在一个类上调用类方法,而我在测试方法中基本上一无所知。我可以检查它的继承和它可能实现的任何协议,但看不到一种简单的方法来调用它的方法而不被 NSInvocation 束缚。下面的代码虽然很粗略,但试图证明我遇到的问题。
@interface ClassA : NSObject
+ (Class)classIsPartialClassOf;
@end
@implementation ClassA
+ (Class)classIsPartialClassOf {
return [NSString class];
}
@end
@interface ClassB : NSObject
@end
@implementation ClassB
- (id)init {
[ClassB testClass:[ClassA class]];
}
+ (void)testClass:(Class)classDecl {
/* obviously if you know the type you can just call the method */
[ClassA classIsPartialClassOf];
/* but in my instance I do not know the type, obviously there are no classmethods to perform selector such as the fictional one below */
[classDecl performSelector:@selector(classIsPartialClassOf)];
}
@end
获取实现的方法似乎返回实例变体,我无法让它们在静态类本身上触发。
我的选择仅限于调用还是我错过了一些明显的东西并且应该踢自己?
预先感谢您的帮助。