NSURL category to parser GET parameters from the URL into a NSDictionary #objective-c #utils #url
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
#import <Foundation/Foundation.h> | |
@interface NSURL (QueryParser) | |
-(NSDictionary*)queryDictionary; | |
@end | |
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
#import "NSURL+QueryParser.h" | |
@implementation NSURL (QueryParser) | |
-(NSDictionary *)queryDictionary | |
{ | |
NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; | |
for (NSString *param in [[self query] componentsSeparatedByString:@"&"]) { | |
NSArray *parts = [param componentsSeparatedByString:@"="]; | |
if([parts count] < 2) continue; | |
[params setObject:[parts objectAtIndex:1] forKey:[parts objectAtIndex:0]]; | |
} | |
return params; | |
} | |
@end |
Probably should replace percent escapes in the keys and values
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code taken from this stackoverflow question, without attribution: http://stackoverflow.com/questions/3997976/parse-nsurl-query-property