根据C#开发人员可以理解的@selector指令是什么?

P.B*_*key 1 objective-c ios

在这里使用选择器的目的是什么?

CADisplayLink* displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(render:)];

资料来源:来自初学者OpenGL es 2.0网站的代码

我读了这个定义

@selector()指令允许您引用已编译的选择器,而不是完整的方法名称.

不幸的是,这并不适合我.我的专长是C#.如果您能将答案与C#中可以实现的类似解决方案联系起来,我将不胜感激.

Ric*_*III 6

选择器声明函数的名称.而已.它与Reflection类非常相似MethodInfo,但使用起来要简单得多.

C#和Objective-C的比较:注意C#代码可能有点偏差,因为我很长时间没有使用它

// C#
using namespace system.reflection;

class someClass {
     void someMethod(object input) {
           string methodName = "doSomething";

           input.getType().getMethod(methodName).invoke(input, new Object[] { });
     }
}

// OBJC
@implementation someClass 

-(void) someMethod:(id) input
{
     SEL methodName = @selector(doSomething);

     [input performSelector:methodName];
}

@end
Run Code Online (Sandbox Code Playgroud)

就a的内部SEL而言,它是一个C-string被放入私有映射中以便在运行时查找速度的方法.