On 28 Sep 2008, at 1:10 pm, Joe Keenan wrote:

                if ([key isEqualToString: @"lnbcolor"])
                {
[lnbLight setTextColor:[NSColor colorFromHexidecimalValue: keyValue]];
                }
                else if ([key isEqualToString: @"lancolor"])
                {
[lanLight setTextColor:[NSColor colorFromHexidecimalValue: keyValue]];
                }

With lots (25 or so) more possible key values, and a half-dozen or more different ways to update the UI element.

An idea.

NSInvocation allows you to turn any method call on any object into an object itself. That could then be stored in a dictionary keyed off the received string, so your long if/else statement reduces to a single line something like:

[[dict objectForKey:key] invoke];

Of course you still need to set up this dictionary in the first place, but if the methods are typically the same but with different targets you can copy and reuse the invocation objects to make this fairly simple.

hth,

Graham
_______________________________________________

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