How to I pass @selector as a parameter?

后端 未结 5 1040
[愿得一人]
[愿得一人] 2021-01-30 07:00

For the method:

[NSThread detachNewThreadSelector:@selector(method:) toTarget:self withObject:(id)SELECTOR];

How do I pass in a @selector? I tr

5条回答
  •  星月不相逢
    2021-01-30 07:05

    You can convert between selectors and string objects using the NSStringFromSelector() and NSSelectorFromString() functions. So you can just pass string objects instead.

    Alternately, if you don't want to change your methods, you can create an NSInvocation to create an invocation for your method call (since it can set up invocations with non-object arguments), and then to call it do [NSThread detachNewThreadSelector:@selector(invoke) toTarget:myInvocation withObject:nil];

提交回复
热议问题