I am not familiar with MultipleDownload , but in case it does not meet your needs, the problem that I accept is that you have one object that is a delegate to many NSURLConnections , and you want to know how to keep them straight .
All delegate methods return NSURLConnection itself as its first parameter. This way you can keep track of which data goes where the testing for which NSURLConnection calls you is. One way to do this is NSDictionary an NSDictionary , which displays a connection to its NSMutableData object. Now the trick is that you cannot make NSURLConnection key in the dictionary, because it does not match NSCopying (and you will not want it). One way around this is to use a connection address, for example:
NSString *key = [NSString stringWithFormat:@"%p", connection];
This will return a unique key for any object (a hexadecimal representation of its address). Some people use description for this purpose, but I do not like it because it is not a well-defined interface. There is no promise that it will be unique. On systems where I do this a lot, I implement the -stringWithFormat: described above -stringWithFormat: in the -uniqueIdentifier method and make it a category on NSObject , so anything can be tracked in the dictionary.
Itβs often easier for me to simply create a small wrapper object so that each object controls its own NSURLConnection , as far as I am sure MultipleDownload does, but this method is useful in a variety of cases, whether you are managing multiple table views or anything else that has a delegate .
EDIT: Replaced by% x I have higher with% p, as pointed out by Peter. He is right, and I did not think correctly. Double checking my code, I actually used% p, having encountered this error before ....
source share