Created
June 29, 2012 11:21
-
-
Save AdamSwinden/3017415 to your computer and use it in GitHub Desktop.
NSURL Query Attributes
This file contains hidden or 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
// | |
// NSURL+QueryAttributes.m | |
// | |
// Created by Adam Swinden on 29/06/2012. | |
// Copyright (c) 2012 The OTHER Media. All rights reserved. | |
// | |
#import "NSURL+QueryAttributes.h" | |
@implementation NSURL (QueryAttributes) | |
- (NSDictionary *)queryAttriutes { | |
NSArray *parts = [self.query componentsSeparatedByString:@"&"]; | |
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:[parts count]]; | |
for (NSString *part in parts) { | |
NSArray *keyValue = [part componentsSeparatedByString:@"="]; | |
if ([keyValue count] != 2) continue; | |
NSString *key = [[keyValue objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; | |
NSString *value = [[keyValue objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; | |
[attributes setObject:value forKey:key]; | |
} | |
return [NSDictionary dictionaryWithDictionary:attributes]; | |
} | |
@end |
This file contains hidden or 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
// | |
// NSURL+QueryAttributes.h | |
// | |
// Created by Adam Swinden on 29/06/2012. | |
// Copyright (c) 2012 The OTHER Media. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSURL (QueryAttributes) | |
- (NSDictionary *)queryAttriutes; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment