Skip to content

Instantly share code, notes, and snippets.

@paingpyi
Created November 11, 2013 04:39
Show Gist options
  • Save paingpyi/7407947 to your computer and use it in GitHub Desktop.
Save paingpyi/7407947 to your computer and use it in GitHub Desktop.
+ (NSDictionary*)getParamFromURL:(NSString*)str
{
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
NSString *url=str;
NSArray *comp1 = [url componentsSeparatedByString:@"?"];
NSString *query = [comp1 lastObject];
NSArray *queryElements = [query componentsSeparatedByString:@"&"];
for (NSString *element in queryElements) {
NSArray *keyVal = [element componentsSeparatedByString:@"="];
if (keyVal.count > 0) {
NSString *variableKey = [keyVal objectAtIndex:0];
NSString *value = (keyVal.count == 2) ? [keyVal lastObject] : nil;
NSLog(@"%@ -> %@",variableKey,value);
[params setValue:value forKey:variableKey];
}
}
return [params copy];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment