Skip to content

Instantly share code, notes, and snippets.

@chiahsien
Created October 1, 2014 04:18
Show Gist options
  • Save chiahsien/fa1230f77a3fc09e629c to your computer and use it in GitHub Desktop.
Save chiahsien/fa1230f77a3fc09e629c to your computer and use it in GitHub Desktop.
AFNetworking-RACExtensions example
- (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