Re: Is it possible for several NSURLConnection instances to share one delegate?
Re: Is it possible for several NSURLConnection instances to share one delegate?
- Subject: Re: Is it possible for several NSURLConnection instances to share one delegate?
- From: Jens Alfke <email@hidden>
- Date: Wed, 25 Jun 2008 08:50:08 -0700
On 25 Jun '08, at 7:17 AM, Ling Wang wrote:
I can't find a way to identify different NSURLConnection instances
in the delegate methods, for NSURLConnection does not offer access
to the NSURLRequest used to initialize it.
If your delegate needs to know which connection is which, then it's a
better design to use a separate delegate object per connection. That
way each delegate can use instance variables to keep whatever state it
wants that's associated with each connection (like the HTTP status,
data downloaded so far, et cetera.)
I've implemented this kind of thing more times than I can count
(really) and always used a single delegate per connection. Typically I
make a class that expresses the higher-level task I'm trying to do —
like "FeedFetcher" or "MusicTrackDownloader" or "BlogPoster" — and
hide all the details including the NSURLConnection inside that class.
The instance then becomes the delegate of the URL connection it starts.
(There was a lengthy discussion of this design on this list a few
months ago.)
—Jens_______________________________________________
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