Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
- delegate:self];
- connectionToInfoMapping =
- CFDictionaryCreateMutable(
- kCFAllocatorDefault,
- 0,
- &kCFTypeDictionaryKeyCallBacks,
- &kCFTypeDictionaryValueCallBacks);
- CFDictionaryAddValue(
- connectionToInfoMapping,
- connection,
- [NSMutableDictionary
- dictionaryWithObject:[NSMutableData data]
- forKey:@"receivedData"]);
- - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
- {
- NSMutableDictionary *connectionInfo =
- CFDictionaryGetValue(connectionToInfoMapping, connection);
- [[connectionInfo objectForKey:@"receivedData"] appendData:data];
- }
- - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
- if (connection == self.savingConnection) {
- [self.savingReturnedData appendData:data];
- }
- else {
- [self.sharingReturnedData appendData:data];
- }
- }
- // This variable must be able to be referenced from - (void)connectionDidFinishLoading:(NSURLConnection *)connection
- NSMutableDictionary *connDictGET = [[NSMutableDictionary alloc] init];
- //...//
- // You can use any object that can be referenced from - (void)connectionDidFinishLoading:(NSURLConnection *)connection
- [connDictGET setObject:anyObjectThatCanBeReferencedFrom forKey:[aConnectionInstanceJustInitiated description]];
- //...//
- // At the delegate method, evaluate if the passed connection is the specific one which needs to be handled differently
- if ([[connDictGET objectForKey:[connection description]] isEqual:anyObjectThatCanBeReferencedFrom]) {
- // Do specific work for connection //
- }
- //...//
- // When the connection is no longer needed, use (NSString *)description as key to remove object
- [connDictGET removeObjectForKey:[connection description]];
- NSMutableDictionary* dict = [NSMutableDictionary dictionary];
- NSValue *key = [NSValue valueWithNonretainedObject:aConnection]
- /* store: */
- [dict setObject:connInfo forKey:key];
- /* lookup: */
- [dict objectForKey:key];
Add Comment
Please, Sign In to add comment