diff options
Diffstat (limited to 'Classes/Fetcher.m')
-rw-r--r-- | Classes/Fetcher.m | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Classes/Fetcher.m b/Classes/Fetcher.m index 3fe162f..6e3e7b3 100644 --- a/Classes/Fetcher.m +++ b/Classes/Fetcher.m @@ -11,11 +11,16 @@ @implementation Fetcher -@synthesize delegate; +@synthesize delegate, payload; + (Fetcher *) initWithString:(NSString *)string andDelegate:(id<FetcherDelegate>)d { + return [Fetcher initWithString:string payload:nil andDelegate:d]; +} + ++ (Fetcher *) initWithString:(NSString *)string payload:(id)p andDelegate:(id <FetcherDelegate>)d { Fetcher *fetcher = [[[Fetcher alloc] init] autorelease]; fetcher.delegate = d; + if (payload != nil) fetcher.payload = p; [fetcher setUrlAndConnect:string]; return fetcher; } @@ -46,11 +51,17 @@ } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { - [delegate connection:connection failedWithError:error]; + if (payload != nil && [(NSObject *)delegate respondsToSelector:@selector(connection:failedWithError:andPayload:)]) + [delegate connection:connection failedWithError:error andPayload:payload]; + else + [delegate connection:connection failedWithError:error]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { - [delegate connection:connection finishedWithData:receivedData]; + if (payload != nil && [(NSObject *)delegate respondsToSelector:@selector(connection:finishedWithData:andPayload:)]) + [delegate connection:connection finishedWithData:receivedData andPayload:payload]; + else + [delegate connection:connection finishedWithData:receivedData]; } - (void) dealloc { |