From 8a93284ca46ef3df7f3853acec3285eeec0d5bb3 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 23 Apr 2012 21:14:27 -0700 Subject: [PATCH] Ah, the wonderful feeling of deleting significant chunks of code --- AFNetworking/AFHTTPClient.m | 31 +++++++------------ AFNetworking/AFHTTPRequestOperation.h | 5 --- AFNetworking/AFHTTPRequestOperation.m | 8 ++--- AFNetworking/AFJSONRequestOperation.m | 4 +-- AFNetworking/AFPropertyListRequestOperation.m | 8 ++--- AFNetworking/AFXMLRequestOperation.m | 6 ++-- 6 files changed, 23 insertions(+), 39 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 5fcb4e1..a97aec9 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -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 { @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]; diff --git a/AFNetworking/AFHTTPRequestOperation.h b/AFNetworking/AFHTTPRequestOperation.h index 7104c41..5aa8407 100644 --- a/AFNetworking/AFHTTPRequestOperation.h +++ b/AFNetworking/AFHTTPRequestOperation.h @@ -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`. diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 3d61013..b229fb7 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -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); }); } diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m index 2f513c9..24ed254 100644 --- a/AFNetworking/AFJSONRequestOperation.m +++ b/AFNetworking/AFJSONRequestOperation.m @@ -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); }); } diff --git a/AFNetworking/AFPropertyListRequestOperation.m b/AFNetworking/AFPropertyListRequestOperation.m index e529a74..ea9d216 100644 --- a/AFNetworking/AFPropertyListRequestOperation.m +++ b/AFNetworking/AFPropertyListRequestOperation.m @@ -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); }); } diff --git a/AFNetworking/AFXMLRequestOperation.m b/AFNetworking/AFXMLRequestOperation.m index d4f4268..79c5272 100644 --- a/AFNetworking/AFXMLRequestOperation.m +++ b/AFNetworking/AFXMLRequestOperation.m @@ -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); }); }