FROM : Shaun Wexler
DATE : Fri Jun 30 21:59:07 2006
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
DATE : Fri Jun 30 21:59:07 2006
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
| Related mails | Author | Date |
|---|---|---|
| Scott Andrew | Jun 28, 20:55 | |
| Mark Stultz | Jun 28, 20:56 | |
| Alan Pearson | Jun 28, 21:01 | |
| Aurélien Hugelé | Jun 29, 16:32 | |
| Finlay Dobbie | Jun 29, 17:17 | |
| Dustin Voss | Jun 30, 02:58 | |
| Jerry Krinock | Jun 30, 17:28 | |
| Jerrod Fowkes | Jun 30, 19:20 | |
| Michael Ash | Jun 30, 20:46 | |
| Shaun Wexler | Jun 30, 21:59 |






Cocoa mail archive

