Created
October 1, 2014 04:18
-
-
Save chiahsien/fa1230f77a3fc09e629c to your computer and use it in GitHub Desktop.
AFNetworking-RACExtensions example
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
- (RACSignal *)fetchSomething { | |
NSString *path = @"path/to/endpoint"; | |
@weakify(self); | |
RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id < RACSubscriber > subscriber) { | |
@strongify(self); | |
[[self rac_GET:path parameters:nil] subscribeNext:^(id responseObject) { | |
NSError *error = nil; | |
NSArray *results = [MTLJSONAdapter modelsOfClass:[XXXModel class] fromJSONArray:responseObject error:&error]; | |
if (error) { | |
[subscriber sendError:error]; | |
} else { | |
[subscriber sendNext:results]; | |
[subscriber sendCompleted]; | |
} | |
} error:^(NSError *error) { | |
[subscriber sendError:error]; | |
}]; | |
return nil; | |
}]; | |
return signal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment