iphone - Objective-C : Is there a way to call class methods on a class object without compiler complaints?

标签 iphone objective-c ios class methods

如果你有一个类对象,有没有办法用它来调用那个类的类方法。例如,如果你有一个类 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/

相关文章:

iphone - iOS6 UIPickerView 内存泄漏问题。

ios - UILabel 动画不正确

ios - 如何以编程方式在 iOS 11+ 中打开设置 > 隐私 > 定位服务?

ios - API 和数据存储 - 微软/服务器

iphone - UITableView 垂直和水平滚动

ios - 具有 204 响应且 Objective-C 中没有内容的 DELETE 请求的巨大延迟

javascript - 静态 map 在使用 wifi 时工作,但在使用蜂窝数据时不工作

c++ - 在 iOS 上使用 C++ 代码,创建静态库或与 Objective C 混合使用?

iphone - 在另一个数组的基础上对数组进行排序

ios - 在隐藏/显示导航栏上查看框架更改?