Skip to content

Instantly share code, notes, and snippets.

@ploddi
Last active October 23, 2019 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ploddi/8952796 to your computer and use it in GitHub Desktop.
Save ploddi/8952796 to your computer and use it in GitHub Desktop.
AFHTTPSessionManager+ReactiveCocoa
@implementation AFHTTPSessionManager (ReactiveCocoa)
- (RACSignal *)rac_signalForHTTPMethod:(NSString *)method
path:(NSString *)path
parameters:(NSDictionary *)parameters {
return [RACSignal create:^(id<RACSubscriber> subscriber) {
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:path relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];
__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
if (error) {
[subscriber sendNext:RACTuplePack(task, responseObject)];
[subscriber sendCompleted];
} else {
[subscriber sendError:error];
}
}];
[task resume];
[subscriber.disposable addDisposable:[RACDisposable disposableWithBlock:^{
[task cancel];
}]];
}];
}
@end
@agassiyzh
Copy link

if (!error) {
[subscriber sendNext:RACTuplePack(task, responseObject)];
[subscriber sendCompleted];
} else {
[subscriber sendError:error];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment