Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save swizzlr/5985563 to your computer and use it in GitHub Desktop.

Select an option

Save swizzlr/5985563 to your computer and use it in GitHub Desktop.
Convenient keypath for finding whether a request completed successfully.
//
// AFHTTPRequestOperation+JLPOperationDidSucceed.h
//
// Created by @swizzlr on 11/07/2013.
// BSD two clause license
//
@class AFHTTPRequestOperation;
@interface AFHTTPRequestOperation (JLPOperationDidSucceed)
-(BOOL)jlp_HTTPRequestOperationDidSucceed;
@end
/*
Mostly for use as a keypath with collection operator for a collection AFHTTPRequestOperations, like so:
[AFHTTPClient enqueueBatchOfHTTPRequestOperations:prioritySyncOperations progressBlock:nil completionBlock:^(NSArray *operations) {
if (![[operations valueForKeyPath:@"@unionOfObjects.jlp_HTTPRequestOperationDidSucceed"] containsObject:@NO]) {
//All operations succeeded: they finished, they had an acceptable status code and acceptable content type
} else {
//At least one didn't: display an error, requeue again...
}
}];
*/
//
// AFHTTPRequestOperation+JLPOperationDidSucceed.m
//
// Created by @swizzlr on 11/07/2013.
// BSD two clause license
//
#import "AFHTTPRequestOperation.h"
#import "AFHTTPRequestOperation+JLPOperationDidSucceed.h"
@implementation AFHTTPRequestOperation (JLPOperationDidSucceed)
- (BOOL)jlp_HTTPRequestOperationDidSucceed {
if (self.isFinished && self.hasAcceptableContentType && self.hasAcceptableStatusCode) {
return YES;
}
return NO;
}
@end
@swizzlr
Copy link
Author

swizzlr commented Jul 12, 2013

APPARENTLY YOU CAN JUST CHECK FOR AN ERROR

(!operation.error)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment