• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: simple AppKit / multithreading question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple AppKit / multithreading question


  • Subject: Re: simple AppKit / multithreading question
  • From: "Dennis C. De Mars" <email@hidden>
  • Date: Sat, 12 Mar 2005 11:24:08 -0800

On Mar 11, 2005, at 5:44 AM, Aurélien Hugelé wrote:

Hi list !

my app is heavily multithreaded, and needs to modify the GUI. I know that the interface mods needs to be done in the main thread.
Its is very convenient to use performSelectorInMainThread: for my secondary threads... but still, i have a question :


most of my threads need to modify the enabled/disabled state or the hidden/shown state of my widgets. I use setEnabled:YES/NO or setHidden:YES/NO

but i can not use performSelectorInMainThread:withObject: here! the argument of this method must be NSObjects ... not BOOL !


There may be a more straightforward way to do it, but you could define a category on NSObject with the following methods:


class MyBoolInvocation;
typedef void (MyBoolIMP) (id, SEL, BOOL);

-(void) performSelectorOnMainThread:(SEL)theSelector withBool:(BOOL)theBool
{
[self performSelectorOnMainThread:@selector(performSelectorWithBoolArg:)
withObject:[MyBoolInvocation newWithSelector:theSelector withBool:theBool]];
}


- (void) peformSelectorWithBoolArg:(MyBoolInvocation*)boolArgs
{
((MyBoolIMP)[self methodForSelector:[boolArgs boolSelector]])(self, [boolArgs boolSelector], [boolArgs boolValue]);
}


The class MyBoolInvocation is just a utility class you would define that has instance variables for a selector and a bool value. You initialize it with newWithSelector:withBool: and retrieve the values with boolSelector and boolValue. It's just a way to pass a struct as a class; I could have used a dictionary but since neither of the values that need to be passed are objects, I thought the auxiliary class was easier for illustrative purposes.

I haven't compiled or tested this, but this gives you the general idea. At least you would only have to do this once for all API methods that need a BOOL, but of course you'd have to have separate methods for int and float.

- Dennis D.
_______________________________________________
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


  • Follow-Ups:
    • Re: simple AppKit / multithreading question
      • From: "Corey O'Connor" <email@hidden>
References: 
 >simple AppKit / multithreading question (From: Aurélien Hugelé <email@hidden>)

  • Prev by Date: Re: Trying to understand "real memory" usage
  • Next by Date: Re: simple AppKit / multithreading question
  • Previous by thread: Re: simple AppKit / multithreading question
  • Next by thread: Re: simple AppKit / multithreading question
  • Index(es):
    • Date
    • Thread