Re: performSelectorOnMainThread
Re: performSelectorOnMainThread
- Subject: Re: performSelectorOnMainThread
- From: glenn andreas <email@hidden>
- Date: Sat, 10 Jan 2009 13:12:45 -0600
On Jan 10, 2009, at 1:00 PM, John Love wrote:
-performSelectorOnMainThread:withObject:waitUntilDone:, according to
Apple docs, is passed a SEL method that "should not have a
significant return value".
I wish it to return a INT and I figure that that qualifies as in-
significant. Given that assumption, my real question is how to
implement it. I call:
[self performSelectorOnMainThread:@selector:mySimpleSelector
withObject:nil waitUntilDone:YES];
(int) mySimpleSelector {
if (whatever) return 0;
else return 1;
}
via my call to -performSelectorOnMainThread, just how do I access -
mySimpleSelector's returned INT? The simplest answer is to not have
a return value at all, but rather store the INTs in a global; but I
figure there is no time like the present to learn to solve this
problem the right way.
The most general solution is to make an NSInvocation (a bit of a pain
the first dozen times you do it), and then have that invocation
performSelectorOnMainThread, with the @selector(invoke). Afterwards,
you can extract the return value from the invocation. This also gives
you the advantage of being able to call things with a much wider range
of number of parameters and parameter types (e.g., passing an NSRect).
(If waitUntilDone: NO is used, it's a bit trickier to figure out when
the thing is done - you'd probably want to use a semaphore - which is
one of the reasons that, in general, you shouldn't have a return value).
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
JSXObjC | the easy way to unite JavaScript and Objective C
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden