Say I want to create an easy way to download an image from Imgur. I do it frequently enough within my app that it'd be nice to not have to go through all of the setup for a NSURLSessionDownloadTask
and configuring it for this use-case, and instead I could use a subclass that would handle most of that configuration.
Is it possible to subclass NSURLSession
in a way that would allow easy interfacing with a specific service?
Say I frequently take the image ID from an Imgur link, for example mFJlvPf
. Instead of setting up the NSURLSession
, setting its configuration, creating the NSURLRequest
, grabbing the result from the NSURL
location it was downloaded from, I could instead just supply the image ID and go to town:
ImgurDownloadTask *downloadTask = [ImgurDownloadTask taskWithImageID:@"mFJlvPf"
progressBlock:^(CGFloat bytesWritten, CGFLoat totalBytesExpectedToBeWritten) {
}
completionBlock:^(UIImage *downloadedImage) {
}];
[downloadTask resume];
Is such a simplification possible? If so, how would I go about doing it?