Last active
October 23, 2019 10:39
-
-
Save ploddi/8952796 to your computer and use it in GitHub Desktop.
AFHTTPSessionManager+ReactiveCocoa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if (!error) {
[subscriber sendNext:RACTuplePack(task, responseObject)];
[subscriber sendCompleted];
} else {
[subscriber sendError:error];
}