Guest User

Untitled

a guest
Nov 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. //
  2. // NSURL+QueryAttributes.m
  3. //
  4. // Created by Adam Swinden on 29/06/2012.
  5. // Copyright (c) 2012 The OTHER Media. All rights reserved.
  6. //
  7.  
  8. #import "NSURLQueryAttributes.h"
  9.  
  10. @implementation NSURL (QueryAttributes)
  11.  
  12.  
  13. - (NSDictionary *)queryAttriutes {
  14.  
  15. NSArray *parts = [self.query componentsSeparatedByString:@"&"];
  16.  
  17. NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:[parts count]];
  18.  
  19. for (NSString *part in parts) {
  20.  
  21. NSArray *keyValue = [part componentsSeparatedByString:@"="];
  22. if ([keyValue count] != 2) continue;
  23.  
  24. NSString *key = [keyValue[0] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
  25. NSString *value = [keyValue[1] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
  26.  
  27. attributes[key] = value;
  28. }
  29.  
  30. return [NSDictionary dictionaryWithDictionary:attributes];
  31. }
  32.  
  33. @end
Add Comment
Please, Sign In to add comment