Re: Is there another way to do performSelectorOnMainThread?
Re: Is there another way to do performSelectorOnMainThread?
- Subject: Re: Is there another way to do performSelectorOnMainThread?
- From: Shaun Wexler <email@hidden>
- Date: Fri, 30 Jun 2006 12:59:07 -0700
On Jun 30, 2006, at 10:20 AM, Jerrod Fowkes wrote:
JAnd a real pain! After using NSInvocation a few times, I realized
"Why am I
putting myself through this torture?"
Allow me to relieve you... ;)
@interface SKWMainThreadProxy : NSProxy
{
id realObject;
BOOL isAsync;
}
- (id)initWithObject:(id)object isAsync:(BOOL)async;
@end
@implementation SKWMainThreadProxy
- (id)initWithObject:(id)object isAsync:(BOOL)async
{
realObject = [object retain];
isAsync = async;
return self;
}
- (void)dealloc
{
[realObject release];
[super dealloc];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
{
return [realObject methodSignatureForSelector:selector];
}
- (void)forwardInvocation:(NSInvocation *)invocation
{
[invocation setTarget:realObject];
if (pthread_main_np()) {
[invocation invoke];
} else {
[invocation retainArguments];
if (!isAsync) {
[invocation performSelectorOnMainThread:@selector
(invoke) withObject:nil waitUntilDone:YES];
} else {
[self performSelectorOnMainThread:@selector(invoke:)
withObject:invocation waitUntilDone:NO];
}
}
}
- (void)invoke:(NSInvocation *)invocation
{
[invocation invoke];
}
+ (NSString *)description
{
return [[super description]
stringByAppendingString:@"_SKWMainThreadProxy"];
}
- (NSString *)description
{
return [realObject description];
}
@end
--
Shaun Wexler
MacFOH
http://www.macfoh.com
"No problem is so formidable that you can't walk away from it." -
Charles Schulz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden