I'm using NSXPCConnection and one of my interface call has a reply block, like this:
- (void)addItem:(NSData *) withLabel:(NSString *) reply:(void (^)(NSInteger rc))reply;
Which I call like this:
__block NSInteger status;
[proxy addItem:data withLabel:@"label" reply:^(NSInteger rc)
{
status = rc;
}
];
My understanding is that the reply block run asynchronously, and potentially after the method returns.
I want to test the return code synchronously, what's the best way to do it?
To clarify further the snippet above: the proxy
object is the remote object obtained from an NSXPCConnection
object using the remoteObjectProxy
method. This is an important detail as this impact on which queue the reply block is invoked.
I propose to use dispatch_semaphore.