[ANN] AMURLLoader
[ANN] AMURLLoader
- Subject: [ANN] AMURLLoader
- From: Andreas Mayer <email@hidden>
- Date: Mon, 13 Sep 2004 03:26:02 +0200
Now that I have figured out NSURLRequest/NSURLConnection, I decided
that I needed a simpler interface to it. This is what I came up with:
+ (AMURLLoader *)loaderWithURL:(NSURL *)url target:(id)target
selector:(SEL)selector userInfo:(id)theUserInfo;
And this is how you use it:
[AMURLLoader loaderWithURL:url target:self
selector:@selector(didReceiveData:context:) userInfo:nil];
- (void)didReceiveData:(NSData *)data context:(NSDictionary *)context
{
if (data) {
int statusCode = 0;
NSURLResponse *response = [context objectForKey:@"response"];
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
statusCode = [(NSHTTPURLResponse *)response statusCode];
NSLog(@"status: %i", statusCode);
}
if (statusCode < 400) {
// do something with data
}
} else {
NSLog(@"error: %@", [(NSError *)[context objectForKey:@"error"]
localizedDescription]);
}
}
Full code here:
<http://www.harmless.de/cocoa.html#urlloader>
Have fun!
Andreas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden