diff --git a/UKMainThreadProxy.h b/UKMainThreadProxy.h index 9fd6ff453..d8792b7a5 100644 --- a/UKMainThreadProxy.h +++ b/UKMainThreadProxy.h @@ -23,7 +23,6 @@ #import - // ----------------------------------------------------------------------------- // Categories: // ----------------------------------------------------------------------------- @@ -35,7 +34,6 @@ @end - // ----------------------------------------------------------------------------- // Classes: // ----------------------------------------------------------------------------- @@ -49,8 +47,11 @@ @interface UKMainThreadProxy : NSObject { IBOutlet id target; + BOOL waitForCompletion; } -(id) initWithTarget: (id)targ; +-(void) setWaitForCompletion: (BOOL)state; + @end diff --git a/UKMainThreadProxy.m b/UKMainThreadProxy.m index cd009a9e5..518b0f914 100644 --- a/UKMainThreadProxy.m +++ b/UKMainThreadProxy.m @@ -23,18 +23,24 @@ #import "UKMainThreadProxy.h" - @implementation UKMainThreadProxy -(id) initWithTarget: (id)targ { self = [super init]; if( self ) + { target = targ; + waitForCompletion = YES; + } return self; } +-(void) setWaitForCompletion: (BOOL)state +{ + waitForCompletion = state; +} // ----------------------------------------------------------------------------- // Introspection overrides: @@ -47,7 +53,6 @@ -(BOOL) respondsToSelector: (SEL)itemAction return( does || [target respondsToSelector: itemAction] ); } - -(id) performSelector: (SEL)itemAction { BOOL does = [super respondsToSelector: itemAction]; @@ -58,13 +63,12 @@ -(id) performSelector: (SEL)itemAction [self doesNotRecognizeSelector: itemAction]; [target retain]; - [target performSelectorOnMainThread: itemAction withObject: nil waitUntilDone: YES]; + [target performSelectorOnMainThread: itemAction withObject: nil waitUntilDone: waitForCompletion]; [target release]; return nil; } - -(id) performSelector: (SEL)itemAction withObject: (id)obj { BOOL does = [super respondsToSelector: itemAction]; @@ -76,14 +80,13 @@ -(id) performSelector: (SEL)itemAction withObject: (id)obj [target retain]; [obj retain]; - [target performSelectorOnMainThread: itemAction withObject: obj waitUntilDone: YES]; + [target performSelectorOnMainThread: itemAction withObject: obj waitUntilDone: waitForCompletion]; [obj release]; [target release]; return nil; } - // ----------------------------------------------------------------------------- // Forwarding unknown methods to the target: // ----------------------------------------------------------------------------- @@ -106,14 +109,13 @@ -(void) forwardInvocation: (NSInvocation*)invocation { [invocation retainArguments]; [target retain]; - [invocation performSelectorOnMainThread: @selector(invokeWithTarget:) withObject: target waitUntilDone: YES]; + [invocation performSelectorOnMainThread: @selector(invokeWithTarget:) withObject: target waitUntilDone: waitForCompletion]; [target release]; } else [self doesNotRecognizeSelector: itemAction]; } - // ----------------------------------------------------------------------------- // Safety net: // ----------------------------------------------------------------------------- @@ -130,7 +132,6 @@ -(id) copyMainThreadProxy // Just in case someone accidentally sends this messag @end - // ----------------------------------------------------------------------------- // Shorthand notation for getting a main thread proxy: // -----------------------------------------------------------------------------