简体   繁体   中英

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? 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?

What do you mean "pass an xmlDocPtr through a selector"? 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: ? 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. The first, and recommended, approach is to create an 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). You should only take this approach if you're comfortable playing with the obj-c runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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