Todd Ditchendorf compares Cocoa and Java and C# when it comes to acessing the GUI thread in their respective GUI toolkit. He ranks the readability as Cocoa then Java then C#.
Here is the Cocoa version, is this readable?
//... inside class definition ...
- (void)doStuffOnWorkerThread {
// ... do worker thread stuff, then...
id arg = ...
[self performSelectorOnMainThread:@selector(doStuffOnMainGUIThread:)
withObject:arg
waitUntilDone:NO];
}
- (void)doStuffOnMainGUIThread:(id)arg {
// update UI, etc...
}
If you are into brackets, self-referential code, name:value, operators as scope modifiers, and methods that look like e-mail addresses then Cocoa is for you. I prefer something more Groovy...
arg = ...
doInThread = {
// update UI, etc...
}
SwingUtilities.invokeAndWait doInThread
Even groovier...
arg = ...
SwingUtilities.invokeAndWait {
// update UI, etc...
}