如果你有一个类对象,有没有办法用它来调用那个类的类方法。例如,如果你有一个类 A 和方法 + (void)foo
定义了你如何在没有编译器警告它找不到方法 foo 的情况下实现类似下面的示例:
A* object = [[A alloc] init];
id objectClass = [object class];
[objectClass foo]; // complains that the method is not found
最佳答案
您不必创建实例来调用类方法。如果必须调用实例方法,请创建实例。
类 A
的方法 + (void)foo
应该被称为,
[A foo];
关于iphone - Objective-C : Is there a way to call class methods on a class object without compiler complaints?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7206450/