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 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> {
|
||||
@private
|
||||
NSStringEncoding _stringEncoding;
|
||||
|
|
@ -523,22 +515,23 @@ static void AFReachabilityCallback(SCNetworkReachabilityRef __unused target, SCN
|
|||
progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock
|
||||
completionBlock:(void (^)(NSArray *operations))completionBlock
|
||||
{
|
||||
AFBatchedOperation *batchedOperation = [[[AFBatchedOperation alloc] init] autorelease];
|
||||
batchedOperation.dispatchGroup = dispatch_group_create();
|
||||
[batchedOperation addExecutionBlock:^{
|
||||
if (completionBlock) {
|
||||
dispatch_group_notify(batchedOperation.dispatchGroup, dispatch_get_main_queue(), ^{
|
||||
__block dispatch_group_t dispatchGroup = dispatch_group_create();
|
||||
dispatch_retain(dispatchGroup);
|
||||
NSBlockOperation *batchedOperation = [NSBlockOperation blockOperationWithBlock:^{
|
||||
dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{
|
||||
if (completionBlock) {
|
||||
completionBlock(operations);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
dispatch_release(dispatchGroup);
|
||||
}];
|
||||
|
||||
|
||||
NSPredicate *finishedOperationPredicate = [NSPredicate predicateWithFormat:@"isFinished == YES"];
|
||||
|
||||
for (AFHTTPRequestOperation *operation in operations) {
|
||||
AFCompletionBlock originalCompletionBlock = [[operation.completionBlock copy] autorelease];
|
||||
operation.completionBlock = ^{
|
||||
dispatch_group_async(batchedOperation.dispatchGroup, dispatch_get_main_queue(), ^{
|
||||
dispatch_group_async(dispatchGroup, dispatch_get_main_queue(), ^{
|
||||
if (originalCompletionBlock) {
|
||||
originalCompletionBlock();
|
||||
}
|
||||
|
|
@ -547,11 +540,11 @@ static void AFReachabilityCallback(SCNetworkReachabilityRef __unused target, SCN
|
|||
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];
|
||||
|
||||
[self enqueueHTTPRequestOperation:operation];
|
||||
|
|
|
|||
|
|
@ -76,11 +76,6 @@
|
|||
*/
|
||||
@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`.
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
|
|||
|
||||
@interface AFHTTPRequestOperation ()
|
||||
@property (readwrite, nonatomic, retain) NSError *HTTPError;
|
||||
@property (readwrite, nonatomic, assign) dispatch_semaphore_t dispatchSemaphore;
|
||||
@end
|
||||
|
||||
@implementation AFHTTPRequestOperation
|
||||
|
|
@ -65,8 +64,6 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
|
|||
@synthesize HTTPError = _HTTPError;
|
||||
@synthesize successCallbackQueue = _successCallbackQueue;
|
||||
@synthesize failureCallbackQueue = _failureCallbackQueue;
|
||||
@synthesize dispatchGroup = _dispatchGroup;
|
||||
@synthesize dispatchSemaphore = _dispatchSemaphore;
|
||||
|
||||
- (id)initWithRequest:(NSURLRequest *)request {
|
||||
self = [super initWithRequest:request];
|
||||
|
|
@ -75,7 +72,6 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
|
|||
}
|
||||
|
||||
self.acceptableStatusCodes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
|
||||
self.dispatchSemaphore = dispatch_semaphore_create(1);
|
||||
self.completionBlock = NULL;
|
||||
|
||||
return self;
|
||||
|
|
@ -173,13 +169,13 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
|
|||
|
||||
if (self.error) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ static dispatch_queue_t json_request_operation_processing_queue() {
|
|||
|
||||
if (self.error) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
@ -135,7 +135,7 @@ static dispatch_queue_t json_request_operation_processing_queue() {
|
|||
|
||||
if (self.JSONError) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,23 +125,23 @@ static dispatch_queue_t property_list_request_operation_processing_queue() {
|
|||
|
||||
if (self.error) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
} 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;
|
||||
|
||||
if (self.propertyListError) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,18 +170,18 @@ static dispatch_queue_t xml_request_operation_processing_queue() {
|
|||
return;
|
||||
}
|
||||
|
||||
dispatch_group_async(self.dispatchGroup, xml_request_operation_processing_queue(), ^(void) {
|
||||
dispatch_async(xml_request_operation_processing_queue(), ^(void) {
|
||||
NSXMLParser *XMLParser = self.responseXMLParser;
|
||||
|
||||
if (self.error) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue