Ah, the wonderful feeling of deleting significant chunks of code
This commit is contained in:
parent
3124db42cd
commit
8a93284ca4
6 changed files with 23 additions and 39 deletions
|
|
@ -41,14 +41,6 @@ NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire
|
||||||
static NSString * const kAFMultipartFormLineDelimiter = @"\r\n"; // CRLF
|
static NSString * const kAFMultipartFormLineDelimiter = @"\r\n"; // CRLF
|
||||||
static NSString * const kAFMultipartFormBoundary = @"Boundary+0xAbCdEfGbOuNdArY";
|
static NSString * const kAFMultipartFormBoundary = @"Boundary+0xAbCdEfGbOuNdArY";
|
||||||
|
|
||||||
@interface AFBatchedOperation : NSBlockOperation
|
|
||||||
@property (readwrite, nonatomic, assign) dispatch_group_t dispatchGroup;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation AFBatchedOperation
|
|
||||||
@synthesize dispatchGroup = _dispatchGroup;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface AFMultipartFormData : NSObject <AFMultipartFormData> {
|
@interface AFMultipartFormData : NSObject <AFMultipartFormData> {
|
||||||
@private
|
@private
|
||||||
NSStringEncoding _stringEncoding;
|
NSStringEncoding _stringEncoding;
|
||||||
|
|
@ -523,22 +515,23 @@ static void AFReachabilityCallback(SCNetworkReachabilityRef __unused target, SCN
|
||||||
progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock
|
progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock
|
||||||
completionBlock:(void (^)(NSArray *operations))completionBlock
|
completionBlock:(void (^)(NSArray *operations))completionBlock
|
||||||
{
|
{
|
||||||
AFBatchedOperation *batchedOperation = [[[AFBatchedOperation alloc] init] autorelease];
|
__block dispatch_group_t dispatchGroup = dispatch_group_create();
|
||||||
batchedOperation.dispatchGroup = dispatch_group_create();
|
dispatch_retain(dispatchGroup);
|
||||||
[batchedOperation addExecutionBlock:^{
|
NSBlockOperation *batchedOperation = [NSBlockOperation blockOperationWithBlock:^{
|
||||||
if (completionBlock) {
|
dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{
|
||||||
dispatch_group_notify(batchedOperation.dispatchGroup, dispatch_get_main_queue(), ^{
|
if (completionBlock) {
|
||||||
completionBlock(operations);
|
completionBlock(operations);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
dispatch_release(dispatchGroup);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
NSPredicate *finishedOperationPredicate = [NSPredicate predicateWithFormat:@"isFinished == YES"];
|
NSPredicate *finishedOperationPredicate = [NSPredicate predicateWithFormat:@"isFinished == YES"];
|
||||||
|
|
||||||
for (AFHTTPRequestOperation *operation in operations) {
|
for (AFHTTPRequestOperation *operation in operations) {
|
||||||
AFCompletionBlock originalCompletionBlock = [[operation.completionBlock copy] autorelease];
|
AFCompletionBlock originalCompletionBlock = [[operation.completionBlock copy] autorelease];
|
||||||
operation.completionBlock = ^{
|
operation.completionBlock = ^{
|
||||||
dispatch_group_async(batchedOperation.dispatchGroup, dispatch_get_main_queue(), ^{
|
dispatch_group_async(dispatchGroup, dispatch_get_main_queue(), ^{
|
||||||
if (originalCompletionBlock) {
|
if (originalCompletionBlock) {
|
||||||
originalCompletionBlock();
|
originalCompletionBlock();
|
||||||
}
|
}
|
||||||
|
|
@ -547,11 +540,11 @@ static void AFReachabilityCallback(SCNetworkReachabilityRef __unused target, SCN
|
||||||
progressBlock([[operations filteredArrayUsingPredicate:finishedOperationPredicate] count], [operations count]);
|
progressBlock([[operations filteredArrayUsingPredicate:finishedOperationPredicate] count], [operations count]);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_group_leave(batchedOperation.dispatchGroup);
|
dispatch_group_leave(dispatchGroup);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
dispatch_group_enter(batchedOperation.dispatchGroup);
|
dispatch_group_enter(dispatchGroup);
|
||||||
[batchedOperation addDependency:operation];
|
[batchedOperation addDependency:operation];
|
||||||
|
|
||||||
[self enqueueHTTPRequestOperation:operation];
|
[self enqueueHTTPRequestOperation:operation];
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,6 @@
|
||||||
*/
|
*/
|
||||||
@property (nonatomic) dispatch_queue_t failureCallbackQueue;
|
@property (nonatomic) dispatch_queue_t failureCallbackQueue;
|
||||||
|
|
||||||
/**
|
|
||||||
The dispatch group on which to call the completion/failure block
|
|
||||||
*/
|
|
||||||
@property (nonatomic) dispatch_group_t dispatchGroup;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A Boolean value determining whether or not the class can process the specified request. For example, `AFJSONRequestOperation` may check to make sure the content type was `application/json` or the URL path extension was `.json`.
|
A Boolean value determining whether or not the class can process the specified request. For example, `AFJSONRequestOperation` may check to make sure the content type was `application/json` or the URL path extension was `.json`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,6 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
|
||||||
|
|
||||||
@interface AFHTTPRequestOperation ()
|
@interface AFHTTPRequestOperation ()
|
||||||
@property (readwrite, nonatomic, retain) NSError *HTTPError;
|
@property (readwrite, nonatomic, retain) NSError *HTTPError;
|
||||||
@property (readwrite, nonatomic, assign) dispatch_semaphore_t dispatchSemaphore;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation AFHTTPRequestOperation
|
@implementation AFHTTPRequestOperation
|
||||||
|
|
@ -65,8 +64,6 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
|
||||||
@synthesize HTTPError = _HTTPError;
|
@synthesize HTTPError = _HTTPError;
|
||||||
@synthesize successCallbackQueue = _successCallbackQueue;
|
@synthesize successCallbackQueue = _successCallbackQueue;
|
||||||
@synthesize failureCallbackQueue = _failureCallbackQueue;
|
@synthesize failureCallbackQueue = _failureCallbackQueue;
|
||||||
@synthesize dispatchGroup = _dispatchGroup;
|
|
||||||
@synthesize dispatchSemaphore = _dispatchSemaphore;
|
|
||||||
|
|
||||||
- (id)initWithRequest:(NSURLRequest *)request {
|
- (id)initWithRequest:(NSURLRequest *)request {
|
||||||
self = [super initWithRequest:request];
|
self = [super initWithRequest:request];
|
||||||
|
|
@ -75,7 +72,6 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.acceptableStatusCodes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
|
self.acceptableStatusCodes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
|
||||||
self.dispatchSemaphore = dispatch_semaphore_create(1);
|
|
||||||
self.completionBlock = NULL;
|
self.completionBlock = NULL;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
@ -173,13 +169,13 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
|
||||||
|
|
||||||
if (self.error) {
|
if (self.error) {
|
||||||
if (failure) {
|
if (failure) {
|
||||||
dispatch_group_async(self.dispatchGroup, self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
failure(self, self.error);
|
failure(self, self.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (success) {
|
if (success) {
|
||||||
dispatch_group_async(self.dispatchGroup, self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
success(self, self.responseData);
|
success(self, self.responseData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ static dispatch_queue_t json_request_operation_processing_queue() {
|
||||||
|
|
||||||
if (self.error) {
|
if (self.error) {
|
||||||
if (failure) {
|
if (failure) {
|
||||||
dispatch_group_async(self.dispatchGroup, self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
failure(self, self.error);
|
failure(self, self.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -135,7 +135,7 @@ static dispatch_queue_t json_request_operation_processing_queue() {
|
||||||
|
|
||||||
if (self.JSONError) {
|
if (self.JSONError) {
|
||||||
if (failure) {
|
if (failure) {
|
||||||
dispatch_group_async(self.dispatchGroup, self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
failure(self, self.error);
|
failure(self, self.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,23 +125,23 @@ static dispatch_queue_t property_list_request_operation_processing_queue() {
|
||||||
|
|
||||||
if (self.error) {
|
if (self.error) {
|
||||||
if (failure) {
|
if (failure) {
|
||||||
dispatch_group_async(self.dispatchGroup, self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
failure(self, self.error);
|
failure(self, self.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dispatch_group_async(self.dispatchGroup, property_list_request_operation_processing_queue(), ^(void) {
|
dispatch_async(property_list_request_operation_processing_queue(), ^(void) {
|
||||||
id propertyList = self.responsePropertyList;
|
id propertyList = self.responsePropertyList;
|
||||||
|
|
||||||
if (self.propertyListError) {
|
if (self.propertyListError) {
|
||||||
if (failure) {
|
if (failure) {
|
||||||
dispatch_group_async(self.dispatchGroup, self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
failure(self, self.error);
|
failure(self, self.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (success) {
|
if (success) {
|
||||||
dispatch_group_async(self.dispatchGroup, self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
success(self, propertyList);
|
success(self, propertyList);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,18 +170,18 @@ static dispatch_queue_t xml_request_operation_processing_queue() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_group_async(self.dispatchGroup, xml_request_operation_processing_queue(), ^(void) {
|
dispatch_async(xml_request_operation_processing_queue(), ^(void) {
|
||||||
NSXMLParser *XMLParser = self.responseXMLParser;
|
NSXMLParser *XMLParser = self.responseXMLParser;
|
||||||
|
|
||||||
if (self.error) {
|
if (self.error) {
|
||||||
if (failure) {
|
if (failure) {
|
||||||
dispatch_group_async(self.dispatchGroup, self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
failure(self, self.error);
|
failure(self, self.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (success) {
|
if (success) {
|
||||||
dispatch_group_async(self.dispatchGroup, self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{
|
||||||
success(self, XMLParser);
|
success(self, XMLParser);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue