Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Is there another way to do performSelectorOnMainThread?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there another way to do performSelectorOnMainThread?



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
References: 
 >Re: Is there another way to do performSelectorOnMainThread? (From: Jerrod Fowkes <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.