Re: Tracking multiple NSURLConnections
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