Last active
July 19, 2018 03:57
-
-
Save Andrewmika/d7d862ae9ceb4aa51dce6c8a4f0b8e3b to your computer and use it in GitHub Desktop.
URL extension
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
- (NSDictionary *)dictQuery { | |
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; | |
NSString *str = self.query; | |
if (str.length && [str rangeOfString:@"="].location != NSNotFound) { | |
NSArray *keyValuePairs = [str componentsSeparatedByString:@"&"]; | |
for (NSString *keyValuePair in keyValuePairs) { | |
NSArray *pair = [keyValuePair componentsSeparatedByString:@"="]; | |
// don't assume we actually got a real key=value pair. start by assuming we only got @[key] before checking count | |
NSString *paramValue = pair.count == 2 ? pair[1] : @""; | |
// CFURLCreateStringByReplacingPercentEscapesUsingEncoding may return NULL | |
parameters[pair[0]] = paramValue ?: @""; | |
} | |
} | |
return parameters; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment