• 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: design pattern for data acquisition in background thread?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >design pattern for data acquisition in background thread? (From: Joe Keenan <email@hidden>)
 >Re: design pattern for data acquisition in background thread? (From: Chris Hanson <email@hidden>)
 >Re: design pattern for data acquisition in background thread? (From: Joe Keenan <email@hidden>)

  • Prev by Date: Re: design pattern for data acquisition in background thread?
  • Next by Date: Re: How to get the current screen resolution on Mac
  • Previous by thread: Re: design pattern for data acquisition in background thread?
  • Next by thread: Re: design pattern for data acquisition in background thread?
  • Index(es):
    • Date
    • Thread