SEL和@selector如何工作? [英] How do SEL and @selector work?
本文介绍了SEL和@selector如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
typedef struct objc_selector *SEL;
在上面的代码中,objective-c中的SEL
类型是指向struct objc_selector
的指针.因此,如果我将SEL
变量设为:
In the code above, SEL
type in objective-c is a pointer to struct objc_selector
. So, if I make a SEL
variable like:
SEL aSel = @selector(instanceMethod) //Like this
会发生什么? @selector
对实例方法instanceMethod
做了什么?
What happens? What did @selector
do to the instance method, instanceMethod
?
推荐答案
@selector
指令仅采用方法名称并返回该方法的适当标识符.此标识符用于确定最终执行选择器时要调用的方法:
The @selector
directive simply takes a method name and returns an appropriate identifier for that method. This identifier is used to determine which method to invoke when the selector does eventually get performed:
SEL aSel = @selector(instanceMethod);
// Calls -instanceMethod on someObject
[someObject performSelector:aSel];
您可以在 Apple的文档中找到详细信息.
You can find details in Apple's documentation.
这篇关于SEL和@selector如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文