On 28.09.2008, at 05:10, Joe Keenan wrote:
The problem with any async method is that I haven't figured an elegant way to know which update code to use for each return value. They're not all the same. Different data elements need different processing to update the UI. When I get a response back asynchronously, I have the variable name and the value, and I have to figure out which UI element it belongs to. The brute force method is a long if/else chain that tests the name of the variable to do it, like:


You could take advantage of the dynamism in the ObjC runtime and build a class or method name from whatever key you have that indicates what to do, then use NSClassFromString() or NSSelectorFromString() (or whatever) and then call that to do the work. I did that for my template engine once:

NSString* className = [NSString stringWithFormat: @"UK [EMAIL PROTECTED]", fieldType];
        Class     theClass = NSClassFromString(className);
        UKTemplateController* theObj = [[theClass alloc] init];
        // From now on I can use all the template controller
// subclasses like the base class, and only they know they're different.

Works like a charm, and the same can be done for selectors on a single object if that's more appropriate.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to