Created
July 16, 2014 03:23
-
-
Save dymx101/49f7a95201e4d1f41fcb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) { | |
NSMutableArray *mutableQueryStringComponents = [NSMutableArray array]; | |
if ([value isKindOfClass:[NSDictionary class]]) { | |
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:)]; | |
for (id nestedKey in [dictionary.allKeys sortedArrayUsingDescriptors:@[ sortDescriptor ]]) { | |
id nestedValue = [dictionary objectForKey:nestedKey]; | |
if (nestedValue) { | |
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)]; | |
} | |
} | |
} else if ([value isKindOfClass:[NSArray class]]) { | |
NSArray *array = value; | |
for (id nestedValue in array) { | |
// [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)]; | |
// NOTICE: the following line is modified by Daniel Dong, the original code is above (commented). | |
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@", key], nestedValue)]; | |
} | |
} else if ([value isKindOfClass:[NSSet class]]) { | |
NSSet *set = value; | |
for (id obj in set) { | |
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue(key, obj)]; | |
} | |
} else { | |
[mutableQueryStringComponents addObject:[[AFQueryStringPair alloc] initWithField:key value:value]]; | |
} | |
return mutableQueryStringComponents; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also added:
@Property (nonatomic, copy) NSString *uuid; // added by Daniel Dong
to class AFURLConnectionOperation