---
title: "Multiple NSURLConnection delegates in Objective-C"  
description: "Multiple NSURLConnection delegates in Objective-C"  
author: "Tarun Kumar"  
published: 2015-08-27  
updated: 2015-08-30  
canonical: https://www.mindstick.com/forum/33428/multiple-nsurlconnection-delegates-in-objective-c  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Multiple NSURLConnection delegates in Objective-C

I have two NSURLConnections. The [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) one depends on the [content](https://www.mindstick.com/articles/13019/get-the-best-content-marketing-pricing-packages-for-your-brand) of the first, so [handling](https://www.mindstick.com/forum/34585/file-handling) the [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) received from the [connection](https://www.mindstick.com/articles/13012/what-makes-ethernet-connection-better-than-wifi) will be different for the two [connections](https://yourviews.mindstick.com/view/87707/baba-siddique-murder-news-his-connections-with-underworld).

I'm just picking up Objective-C and I would like to know what the proper way to implement the delegates is.

```
NSURL *url=[NSURL URLWithString:feedURL];NSURLRequest *urlR=[[[NSURLRequest alloc] initWithURL:url] autorelease];NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:urlR delegate:self];
```

I don't want to use [self](https://www.mindstick.com/articles/44535/smart-ways-to-secure-self-storage-facilities) as the [delegate](https://www.mindstick.com/articles/777/delegate-and-event-in-c-sharp), how do I [define](https://yourviews.mindstick.com/audio/1110/lifestyles-choices-that-define-our-lives) two connections with different delegates?

```
NSURLConnection *c1 = [[NSURLConnection alloc] initWithRequest:url delegate:handle1];NSURLConnection *c2 = [[NSURLConnection alloc] initWithRequest:url delegate:handle2];
```

How would do i create handle1 and handle2 as implementations? Or [interfaces](https://www.mindstick.com/articles/12100/interfaces-in-java-real-life-example)? I don't really get how you would do this.

Any help would be awesome.\

## Replies

### Reply by Anonymous User

In your sample, you alloc a DownloadDelegate object without ever init'ing it.\
DownloadDelegate *dd = [DownloadDelegate alloc];

This is dangerous. Instead:\
DownloadDelegate *dd = [[DownloadDelegate alloc] init];

Also, it's not strictly necessary to declare your delegate response methods in your @interface declaration (though it won't hurt, of course). Finally, you'll want to make sure that you implement connection:didFailWithError: and connectionDidFinishLoading: to -release your DownloadDelegate object, otherwise you'll leak.


---

Original Source: https://www.mindstick.com/forum/33428/multiple-nsurlconnection-delegates-in-objective-c

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
