• 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: Tracking multiple NSURLConnections
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tracking multiple NSURLConnections


  • Subject: Re: Tracking multiple NSURLConnections
  • From: Greg Guerin <email@hidden>
  • Date: Tue, 29 Jun 2010 13:29:43 -0700

If I have lots of connections, say two dozen, or say I'm spawning connections continuously, would this be the most efficient way of doing this? I'd likely store them in an NSArray and iterate/compare until I find the right one. There could be lots of comparisons.


Use NSSet instead of NSArray. It makes searching and some other things faster and simpler.

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ Foundation/Classes/NSSet_Class/Reference/Reference.html


OK, makes sense. But is what I've done so wrong or is it just that there are better ways?


It's not really a question of wrong, but one of appropriateness to scale. If you only have one outstanding connection, then you don't need to distinguish multiple connections, by definition. If you do need to distinguish multiple connections, then you should use an approach that works at that scale. With a few, simple comparison is easy and clear. Beyond that, it becomes unwieldy. Beyond multiple dozens and into hundreds, you have other problems.

BTW, using a different delegate for each connection can encapsulate connection identity. That is, your delegate object changes depending on what the data produced by the connection is intended for. Each connection delivers results to its delegate, which then performs the task appropriate for that connection's data. There is no if statement, no array to search, etc. at data-retrieval time. Each paired connection + delegate defines the entire processing path for the data. No repeated lookups or decision-trees are needed.

  -- GG

_______________________________________________

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


  • Prev by Date: Re: Tracking multiple NSURLConnections
  • Next by Date: Re: Redirect NSLog to stdout?
  • Previous by thread: Re: Tracking multiple NSURLConnections
  • Next by thread: Subclass UIScrollView
  • Index(es):
    • Date
    • Thread