I am using NSURLConnection to load data from a response. It works as it should, the delegate method connectionDidFinishLoading has the connection instance with the data I need. The problem is that I want to pass some information along with the request so that I can get it when the connection finishes loading:
- User wants to share the content of a URL via (Facebook, Twitter,
C, D). NSURLConnectionis used to get the content of the URL- Once I have the content, I use the SL framework
SLComposeViewController:composeViewControllerForServiceTypeand need
to give it the service type - At this point I don’t know what service the user selected in step 1. I’d like to send that with the
NSURLConnection.
Can I extend NSURLConnection with a property for this? That seems very heavy-handed. There must be a “right way” to do this.
Many Thanks
Assuming you don’t need the delegate-based version of the
NSURLConnectionprocess for some other reason, this is a good use case for the block-based version:Since blocks can capture variables from their surrounding scope, you can just use whatever context you already had for the user’s choice of service inside the
NSURLConnection‘s completion block.If you’re still wed to the delegate-based
NSURLConnectionAPI for whatever reason, you can always use an ivar or some other piece of state attached to whatever object is handling this process: setself.serviceTypeor some such when the user chooses a service, then refer back to it once you get your content from theNSURLConnectionDelegatemethods and are ready to show a compose view.