Skip to content

Instantly share code, notes, and snippets.

@karlbecker
Last active January 21, 2016 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlbecker/3c9084dce58e80437697 to your computer and use it in GitHub Desktop.
Save karlbecker/3c9084dce58e80437697 to your computer and use it in GitHub Desktop.
NSURLComponents queryItems as an NSDictionary
//
// NSURLComponents+QueryItemsDictionary.m
// browzine
//
// Created by Karl Becker on 1/20/16.
// Copyright © 2016 Third Iron. All rights reserved.
//
// Requires https://github.com/grav/nsarray-functional
#import <Foundation/Foundation.h>
#import "NSArray+Functional.h"
@interface NSURLComponents (QueryItemsDictionary)
- (NSDictionary *)queryItemsDictionary;
@end
@implementation NSURLComponents (QueryItemsDictionary)
- (NSDictionary *)queryItemsDictionary {
NSMutableDictionary *queryItems = [NSMutableDictionary dictionary];
[self.queryItems applyBlock:^(NSURLQueryItem *queryItem) {
[queryItems setObject:queryItem.value forKey:queryItem.name];
}];
return queryItems;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment