Re: NSURLDownload and userInfo
Re: NSURLDownload and userInfo
- Subject: Re: NSURLDownload and userInfo
- From: Ben Lachman <email@hidden>
- Date: Mon, 10 Mar 2008 21:35:53 -0400
Alternatively, if you're managing more than two requests at a time
you can declare a mutable array of connections and then build a
dictionary for each connection that includes any info you want you
delegate to have available. I have a method that build the
connection dict for a connection like this:
[self _connectionDictionaryWithConnection:[NSURLConnection
connectionWithRequest:postRequest delegate:self] ofType:type
andObject:object selector:aSelector context:contextInfo];
which uses this method:
- (NSDictionary *)_connectionDictionaryWithConnection:
(NSURLConnection *)connection ofType:(NSString *)type andObject:(id)
object selector:(SEL)aSelector context:(void *)contextInfo {
return [NSDictionary dictionaryWithObjectsAndKeys:
connection, @"connection",
type, @"type",
[NSMutableData data], @"data",
object, @"object",
contextInfo, @"context",
NSStringFromSelector(aSelector), @"selector",
nil];
}
and then to retrieve it I call:
- (NSDictionary *)_connectionDictionaryForConnection:(NSURLConnection
*)connection {
NSArray *matchArray = [connections filteredArrayUsingPredicate:
[NSPredicate predicateWithFormat:@"connection == %@", connection]];
if( [matchArray count] > 1 )
NSLog(@"multiple connection matches\n");
if( ! isEmpty(matchArray) )
return [matchArray lastObject];
else
return nil;
}
Perhaps not the most efficient, but work for my 10-15 concurrent
often changing connections.
HTH,
->Ben
--
Ben Lachman
Acacia Tree Software
http://acaciatreesoftware.com
email@hidden
740.590.0009
On Mar 10, 2008, at 9:22 AM, Clint Shryock wrote:
Do you have two instances of NSURLDownload?
if they are declared in the .h file you could test for equality in the
downloadDidFinish:
delegate method.
- (void)downloadDidBegin:(NSURLDownload *)download {
if(download == myNSURLDownloadA) {
// something for a
}
if(download == myNSURLDownloadB) {
// something for b
}
}
2008/3/9 Trygve Inda <email@hidden>:
I am using NSURLDownload and NSURLRequest to download 2 different
types of
data (A & B)... Both of which are related to the same class so
they share
delegate methods.
In my delegate, when there is an error or successful completion I
need to
call one "process method" for A and a different one for B. To
enable this,
is there a way to attach some sort of userInfo type (even an int) to
either
the NSURLDownload or NSURLRequest... Or should I subclass one of
them to
add
a variable?
_______________________________________________
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