How can I dynamically create a selector at runtime with Objective-C?

前端 未结 4 1157
北海茫月
北海茫月 2020-12-07 13:59

I know how to create a SEL at compile time using @selector(MyMethodName:) but what I want to do is create a selector dynamically from an NSSt

4条回答
  •  星月不相逢
    2020-12-07 14:42

    According to the XCode documentation, your psuedocode basically gets it right.

    It’s most efficient to assign values to SEL variables at compile time with the @selector() directive. However, in some cases, a program may need to convert a character string to a selector at runtime. This can be done with the NSSelectorFromString function:

    setWidthHeight = NSSelectorFromString(aBuffer);

    Edit: Bummer, too slow. :P

提交回复
热议问题