Objective-C va_list and selectors

穿精又带淫゛_ 提交于 2019-12-04 17:46:38

You can pass anything you want into the runtime function objc_msgSend.

objc_msgSend(del, @selector(logEventWithFormat:arguments:), format, argList);

It's the most powerful way of sending a manually constructed message.

However, it's not clear that you need to perform the invocation this way. As KennyTM pointed out, in the code you have, you could invoke the method directly.

You can't use -performSelector:withObject:withObject: because va_list simply isn't an "object". You need to use NSInvocation.

Or simply call

[del logEventWithFormat:format arguments:argList];

As far as I know, it can't be done. You can't use -performSelector:withObject:withObject: because as @KennyTM points out, a va_list isn't an object.

However, you also cannot use NSInvocation. The documentation straight up says so:

NSInvocation does not support invocations of methods with either variable numbers of arguments or union arguments.

Since these are the two ways of invoking a method by selector, and neither seems to work, I'm going to go with the "can't be done" answer, unless you invoke the method directly and pass the va_list as an argument.

Perhaps @bbum will show up and enlighten us further. =)

I haven't done it that way before, but the simple solution I've often used is to box/unbox either an NSMutableArray or an NSMutableDictionary for the withObject parameter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!