从 Method 到 SEL 的类型转换
我正在使用 Objective-C 运行时库函数 class_copyMethodList() 来获取类中所有方法的列表。然后如何将这些 Method 类型对象转换为可用的 SEL 类型对象?
I’m using the Objective-C runtime library, function class_copyMethodList(), to get a list of all the methods in my class. How do I then convert those type Method objects into usable type SEL objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对返回的 Method 对象运行函数
method_getName()
。Run the function
method_getName()
on the returned Method objects.几年前我这样做是为了提取类方法的所有名称。您可以使用 NSSelectorFromString() 从每个名称中获取 SEL。
I did this a couple of years back to extract all the names of a class's methods. You could use NSSelectorFromString() to get the SEL from each name.
假设您知道方法的名称,您可以使用 NSSelectorFromString 函数将其转换为选择器。
Apple 在他们的 Objective C 教程。
Assuming you have the name of the method, you can convert it to a selector using the
NSSelectorFromString
function.Apple discusses this in their Objective C tutorial.