Re: design pattern for data acquisition in background thread?
Re: design pattern for data acquisition in background thread?
- Subject: Re: design pattern for data acquisition in background thread?
- From: Graham Cox <email@hidden>
- Date: Sun, 28 Sep 2008 15:51:36 +1000
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@hidden)
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:
This email sent to email@hidden