ReactiveMantle 0.1.0

ReactiveMantle 0.1.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Mar 2015

Maintained by Martin Fernandez.



 
Depends on:
ReactiveCocoa~> 2.4
Mantle~> 1.5
 

Usage

ReactiveMantle transforms NSDictionary values from a RACSignal into Mantle objects, just that.

For example, if we use AFNetworking-RACExtensions for Networking, you code could look like this:

Mantle model:

#import <Mantle/Mantle.h>

@interface Product : MTLModel <MTLJSONSerializing>

@property (nonatomic, copy) NSNumber *id;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSNumber *price;

@end

@implementation Product

#pragma mark - MTLJSONSerializing

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
  return @{
           @"id" : @"id",
           @"name" : @"name",
           @"price" : @"price"
           };
}

@end

Then we can make a request and transform the signal value like this:

@interface APIClient : NSObject

@property (strong, nonatomic) AFHTTPSessionManager *manager;

- (RACSignal *)getProducts;

@end

@implementation APIClient

- (RACSignal *)getProducts {
  NSString *path = @"/products.json";

  return [[[[self.manager rac_GET:path parameters:nil]
  replayLazily]
  parseResponseForClass:[Product class]]
  transformError];
}

@end

Take a look at the documentation for more information. :)

Installation

Author

Martin Fernandez, [email protected]

License

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