This is indeed possible. I would approach the problem like this:
@interface ImgurClient : NSObject
+(instancetype) sharedClient;
-(NSURLSessionDownloadTask*)taskWithImageID:(NSString*)imageId
progressBlock:(void (^)(/*TBD*/))progressBlock
completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler
@end
@implementation ImgurClient {
NSURLSession* session;
}
+(instancetype) sharedClient {
static ImgurClient* _sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[ImgurClient alloc] init];
});
return _sharedClient;
}
-(id) init {
self = [super init];
if (self) {
// Additional initialisation, setting up NSURLSession, etc
}
}
-(NSURLSessionDownloadTask*)taskWithImageID:(NSString*)imageId
progressBlock:(void (^)(/*TBD*/))progressBlock
completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler {
// Build URL, store progress handler, create download task
}
That is, there's a ImgurClient
object that is a singleton and whenever you need to do a request you use it like [[ImgurClient sharedClient] taskWithImageId:@"..." ....];
.