Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
NSURL category to parser GET parameters from the URL into a NSDictionary #objective-c #utils #url
#import <Foundation/Foundation.h>
@interface NSURL (QueryParser)
#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;
Copy link

Code taken from this stackoverflow question, without attribution:

Copy link

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