• 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: Uli Kusterer <email@hidden>
  • Date: Sun, 28 Sep 2008 05:51:50 +0200

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 %@TemplateController", 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@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: Need to override +(Class) class?
  • Next by Date: Re: showing window causes EXC_BAD_ACCESS
  • 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