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?
1 Answers
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.

- 182,031
- 33
- 381
- 347
-
The reason I am trying to pass the object into a selector is because all my calculations and loading is done on a background thread and I need to send the computed/loaded data onto the main thread for GUI purposes. – Seb May 24 '12 at 13:22
-
@Seb: In that case the easiest solution is just `dispatch_async(dispatch_get_main_queue(), ^{ /* do your main queue work here */ })` (or use `dispatch_sync()` if you really really need to, standard caveats about synchronous cross-thread access go here). – Lily Ballard May 24 '12 at 19:23