Refactoring some loops to fast enumeration.
This commit is contained in:
parent
43b05d7ceb
commit
7745e8f444
1 changed files with 11 additions and 11 deletions
|
|
@ -149,22 +149,22 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
|
||||||
NSDictionary *dictionary = 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
|
// 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:)];
|
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) {
|
for (id nestedKey in [dictionary.allKeys sortedArrayUsingDescriptors:@[ sortDescriptor ]]) {
|
||||||
id nestedValue = [dictionary objectForKey:nestedKey];
|
id nestedValue = dictionary[nestedKey];
|
||||||
if (nestedValue) {
|
if (nestedValue) {
|
||||||
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)];
|
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)];
|
||||||
}
|
}
|
||||||
}];
|
}
|
||||||
} else if ([value isKindOfClass:[NSArray class]]) {
|
} else if ([value isKindOfClass:[NSArray class]]) {
|
||||||
NSArray *array = value;
|
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)];
|
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
|
||||||
}];
|
}
|
||||||
} else if ([value isKindOfClass:[NSSet class]]) {
|
} else if ([value isKindOfClass:[NSSet class]]) {
|
||||||
NSSet *set = value;
|
NSSet *set = value;
|
||||||
[set enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
|
for (id obj in set) {
|
||||||
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue(key, obj)];
|
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue(key, obj)];
|
||||||
}];
|
}
|
||||||
} else {
|
} else {
|
||||||
[mutableQueryStringComponents addObject:[[AFQueryStringPair alloc] initWithField:key value:value]];
|
[mutableQueryStringComponents addObject:[[AFQueryStringPair alloc] initWithField:key value:value]];
|
||||||
}
|
}
|
||||||
|
|
@ -605,12 +605,12 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
|
||||||
originalCompletionBlock();
|
originalCompletionBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
__block NSUInteger numberOfFinishedOperations = 0;
|
NSUInteger numberOfFinishedOperations = 0;
|
||||||
[operations enumerateObjectsUsingBlock:^(id obj, __unused NSUInteger idx, __unused BOOL *stop) {
|
for (NSOperation *operation in operations) {
|
||||||
if ([(NSOperation *)obj isFinished]) {
|
if (operation.isFinished) {
|
||||||
numberOfFinishedOperations++;
|
numberOfFinishedOperations++;
|
||||||
}
|
}
|
||||||
}];
|
}
|
||||||
|
|
||||||
if (progressBlock) {
|
if (progressBlock) {
|
||||||
progressBlock(numberOfFinishedOperations, [operations count]);
|
progressBlock(numberOfFinishedOperations, [operations count]);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue