I'm new with Swift, and that's why I'm new with Reactive Cocoa v5 or Reactive Swift.
Previously I used RACSignal with RAC 2.x and I liked to do something like this:
- (RACSignal *)signalForGET:(NSString *)URLString parameters:(NSDictionary *)parameters {
return [RACSignal createSignal:^RACDisposable *(id <RACSubscriber> subscriber) {
AFHTTPRequestOperation *op = [self GET:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
[subscriber sendNext:responseObject];
[subscriber sendCompleted];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[subscriber sendError:error];
}];
return [RACDisposable disposableWithBlock:^{
[op cancel];
}];
}];
}
And here I loved that it cancels request on disposable, and also I could cancel it manually by calling dispose
method on the returned signal.
I'm a little bit confused about all this stuff in Reactive Swift, like SignalProducers etc.
Please give me example how to implement the same with newest Swift/ReactiveSwift/ReactiveCocoa versions. Main requirement is to have ability to cancel request (or dispose signal) wherever I want, and to have request automatically getting cancelled on dispose