title: Organize multiple NSURLSessionTasks
body: <p>I have an iOS app that can download files from a website. I have created a <code>NSURLSession</code> in a class <code>Downloads</code> to manage them. The <code>Downloads</code> class has a <code>NSMutableArray</code> that keeps track of all current and past downloads using my <code>DownloadItem</code> objects. I am not happy with this setup.</p>
  
  <p>Currently, I have to have the <code>Downloads</code> class as the delegate for all downloads. I see no way to assign the delegate of each <code>NSURLSessionDownloadTask</code> to a <code>DownloadItem</code> object. So, I have to keep it assigned to my <code>Downloads</code> object and then have it figure out which way <code>DownloadItem</code> to forward the message on to.</p>
  
  <p>Currently I do this by making an NSMutableDictionary called <code>tasksDictionary</code> in the <code>Downloads</code> and use the <code>taskIdentifier</code> as a key.</p>
  
  <pre><code>return [self.tasksDictionary objectForKey:[NSNumber numberWithInteger:task.taskIdentifier]];
  </code></pre>
  
  <p>This seems to work, but it doesn't seem the most efficient method. I'm also concerned that I saw the first taskIdentifier created was <code>0</code> which will make it difficult to discern the difference between a completed task and the first task.</p>
  
  <p>Is there a better way to keep track of these things? Is there a way to assign a new delegate for a task?</p>