• 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: Is it possible for several NSURLConnection instances to share one delegate?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Is it possible for several NSURLConnection instances to share one delegate? (From: Ling Wang <email@hidden>)

  • Prev by Date: Re: Newbie question: instantiate a class in its header file OR in IB
  • Next by Date: Re: Is it possible for several NSURLConnection instances to share one delegate?
  • Previous by thread: Re: Is it possible for several NSURLConnection instances to share one delegate?
  • Next by thread: Re: Xcode eats 100% CPU and more while typing
  • Index(es):
    • Date
    • Thread