Skip to content

Rahul-Mayani/RRReactiveNetworking

Repository files navigation

RRReactiveNetworking

License: MIT Platform

Managing Nested Asynchronous Callbacks in Objective-C using ReactiveCocoa by AFNetworking

Requirements

Use of the following Cocoapods is required:

Installation

Manually

  1. Download the project.
  2. Add RRApiManager.h & RRApiManager.m with necessary files in your project.
  3. Congratulations!

Usage example

A RACSignal should wrap an operation with an asynchronous callback block.

The last signal to run should call subscribeNext for receiving output values. If no output values are available, subscribeNext can be replaced by subscribeCompleted or subscribeError.

Any intermediate step is defined by flattenMap. The parameter in flattenMap corresponds to the data from the next signal. It also takes a return value, which is the subsequent signal to run. The two signals are written top-down and are executed top-down.

We don’t want to strongly retain self: in ARC, we introduce __weak. Also, the extra square brackets at start and end are ugly in Objective-C’s implementation of functional reactive programming.

@weakify(self);

NSDictionary *param = @{@"key": @"test"};
[[[[[RRApiManagerShared postAPICallURL:API_URL header:nil param:param]
flattenMap:^(id responseOfPostAPI) {
    NSLog(@"%@",responseOfPostAPI);
    return [RRApiManagerShared getAPICallURL:API_URL header:nil];
}]
subscribeOnBackgroundAndDeliverOnMainThread]
subscribeNext:^(id responseGetAPI) {
    NSLog(@"%@",responseGetAPI);
} error:^(NSError * error) {
    NSLog(@"%@",error.localizedDescription);
}] rac_deallocDisposable];

To run the project, clone the repo, and run pod install from the RRReactiveNetworking directory first.

Contribute

We would love you for the contribution to RRReactiveNetworking, check the LICENSE file for more info.

License

RRReactiveNetworking is available under the MIT license. See the LICENSE file for more info.

Releases

No releases published

Packages

No packages published