Bladeren bron

Refactoring some loops to fast enumeration.

Oliver Letterer 12 jaren geleden
bovenliggende
commit
7745e8f444
1 gewijzigde bestanden met toevoegingen van 11 en 11 verwijderingen
  1. 11 11
      AFNetworking/AFHTTPClient.m

+ 11 - 11
AFNetworking/AFHTTPClient.m

@@ -149,22 +149,22 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
         NSDictionary *dictionary = value;
         // Sort dictionary keys to ensure consistent ordering in query string, which is important when deserializing potentially ambiguous sequences, such as an array of dictionaries
         NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(caseInsensitiveCompare:)];
-        [[[dictionary allKeys] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]] enumerateObjectsUsingBlock:^(id nestedKey, __unused NSUInteger idx, __unused BOOL *stop) {
-            id nestedValue = [dictionary objectForKey:nestedKey];
+        for (id nestedKey in [dictionary.allKeys sortedArrayUsingDescriptors:@[ sortDescriptor ]]) {
+            id nestedValue = dictionary[nestedKey];
             if (nestedValue) {
                 [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)];
             }
-        }];
+        }
     } else if ([value isKindOfClass:[NSArray class]]) {
         NSArray *array = value;
-        [array enumerateObjectsUsingBlock:^(id nestedValue, __unused NSUInteger idx, __unused BOOL *stop) {
+        for (id nestedValue in array) {
             [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
-        }];
+        }
     } else if ([value isKindOfClass:[NSSet class]]) {
         NSSet *set = value;
-        [set enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
+        for (id obj in set) {
             [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue(key, obj)];
-        }];
+        }
     } else {
         [mutableQueryStringComponents addObject:[[AFQueryStringPair alloc] initWithField:key value:value]];
     }
@@ -605,12 +605,12 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
                     originalCompletionBlock();
                 }
 
-                __block NSUInteger numberOfFinishedOperations = 0;
-                [operations enumerateObjectsUsingBlock:^(id obj, __unused NSUInteger idx, __unused BOOL *stop) {
-                    if ([(NSOperation *)obj isFinished]) {
+                NSUInteger numberOfFinishedOperations = 0;
+                for (NSOperation *operation in operations) {
+                    if (operation.isFinished) {
                         numberOfFinishedOperations++;
                     }
-                }];
+                }
 
                 if (progressBlock) {
                     progressBlock(numberOfFinishedOperations, [operations count]);