Skip to content

Instantly share code, notes, and snippets.

@ploddi ploddi/gist:8952796
Last active Oct 23, 2019

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Mar 5, 2014

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
You can’t perform that action at this time.