Skip to content

Instantly share code, notes, and snippets.

@brynbellomy
Created April 20, 2013 15:07
Show Gist options
  • Select an option

  • Save brynbellomy/5426288 to your computer and use it in GitHub Desktop.

Select an option

Save brynbellomy/5426288 to your computer and use it in GitHub Desktop.
RAC: async request factory method returning a RACSignal
- (RACSignal *)enqueueRequestWithMethod:(NSString *)method
path:(NSString *)path
parameters:(NSDictionary *)parameters
{
RACReplaySubject *subject = [RACReplaySubject subject];
NSURLRequest *request = [self requestWithMethod:method path:path parameters:parameters];
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
[subject sendNext:responseObject];
[subject sendCompleted];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[subject sendError:error];
}];
[self enqueueHTTPRequestOperation:operation];
return subject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment