Skip to content

Jigneshmayani90/ReactiveNetworking

Repository files navigation

ReactiveNetworking

Nested API calls by AFNetworking with reactive ObjC

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 ReactiveNetworking, check the LICENSE file for more info.

License

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

About

Nested API calls by AFNetworking with reactive ObjC

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published