简体   繁体   English

将xmlDocPtr对象传递给选择器

[英]Passing a xmlDocPtr object into a selector

I don't know how much I can say about the app that I am creating due to some NDA functionality, even if it may not be new I still would like to save myself, but I was wondering if there was a way to pass a xmlDocPtr through a selector? 由于某些NDA功能,我不知道该如何说说我正在创建的应用程序,即使它可能不是新的,我仍然想保存自己,但是我想知道是否有办法通过xmlDocPtr通过选择器? If so how is this possible? 如果可以,这怎么可能? I know that I can take a char* and convert it to a NSString, but does a xmlDocPtr have the same capability to convert to an id type? 我知道我可以将char *转换为NSString,但是xmlDocPtr是否具有相同的转换为id类型的功能?

What do you mean "pass an xmlDocPtr through a selector"? 您是什么意思“通过选择器传递xmlDocPtr”? Given that you seem to be trying to convert it to an obj-c object, I'm assuming you're trying to use -performSelector:withObject: ? 假设您似乎正在尝试将其转换为obj-c对象,那么我假设您正在尝试使用-performSelector:withObject: Because if you're just calling the method, there's no restriction on types of arguments. 因为如果只调用方法,则对参数类型没有限制。

If you need to dynamically call a selector that takes a non-obj-c object, you have two alternatives. 如果需要动态调用采用非obj-c对象的选择器,则有两种选择。 The first, and recommended, approach is to create an NSInvocation . 第一种也是推荐的方法是创建NSInvocation

SEL sel = // selector that takes xmlDocPtr
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[target methodSignatureForSelector:sel]];
[invocation setSelector:sel];
[invocation setArgument:&xmlDocPtr atIndex:2]; // 0 is self, 1 is _cmd
[invocation invokeWithTarget:target];
// if you need a return value, use
// typeOfReturnValue retVal;
// [invocation getReturnValue:&retVal];

The second is to cast objc_msgSend() to the appropriate function type and call that, although this gets more complicated (and somewhat architecture-dependent) if there's floating point values or struct values involved (as method arguments or return value). 第二个方法是将objc_msgSend()转换为适当的函数类型并调用它,尽管如果涉及浮点值或结构值(作为方法参数或返回值),则这将变得更加复杂(并且在某种程度上取决于体系结构)。 You should only take this approach if you're comfortable playing with the obj-c runtime. 仅当您愿意使用obj-c运行时时才应采用这种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM