Code Monkey home page Code Monkey logo

nsurl-querydictionary's Introduction

Build Status Build Status

NSURL-QueryDictionary

Just some simple NSURL, NSString and NSDictionary categories to make working with URL queries more pleasant.

  • -[NSURL uq_queryDictionary] extract the URL's query string as key/value pairs.
  • -[NSURL uq_URLByAppendingQueryDictionary:] append the specified key/value pairs to the URL, with existing query handled. Note that behaviour for overlapping keys/values is undefined.
  • -[NSURL uq_URLByReplacingQueryWithDictionary:] create a copy of the URL with its query component replaced by that specified in the dictionary.
  • -[NSURL uq_URLByRemovingQuery] create a copy of the URL with the query component completely removed.

The parsing components of the above are also available separately as:

  • -[NSString uq_URLQueryDictionary] split a valid query string into key/value pairs.
  • -[NSDictionary uq_URLQueryString] the reverse of above; create a URL query string from an NSDictionary instance.

The methods returning URL instances have withSortedKeys: partner methods that sort the dictionary's keys alphabetically with YES. This is so as to make the generated URL's string deterministic, with is necessary if you're unit testing URLs created using these methods - at least this was helpful for me!

Queries with empty values are converted to NSNull and vice versa as of v0.0.5.

##Version history

###v1.1.0

  • Now has methods to create URL copies with the query removed, or replaced with a specified query dictionary.

###v1.0.3

Bug fixes courtesy of Jan Berkel, Elliot Chance and Grzegorz Nowicki. 1, 2, 3.

###v1.0.2

###v0.0.7

Fixed a potential issue/static analyser false positive with thanks to Adam Lickel.

###v0.0.6

Added optional flag to sort the dictionary's keys alphabetically when generating the URL. This makes the generated URLs more deterministic, which helps (for example) if you are running unit tests to inspect your URLs and would like to test the absolute string, rather than having to recreate a query dictionary.

###v0.0.5

Covered an additional empty value case - URL query component has separator, but empty value.

###v0.0.4

Added handling for keys with no value, empty value or NSNull.

###v0.0.3

Split the query string parsing components out into NSString and NSDictionary categories for additional flexibility.

###v0.0.2

Added support for dictionary keys other than NSString. Currently just uses -description, but this is ok for NSNumber and NSDate and a few others, so may be sufficient.

###v0.0.1

Initial release.

Have fun!

MIT Licensed >> [email protected]

nsurl-querydictionary's People

Contributors

elliotchance avatar jberkel avatar lickel avatar wikia-gregor avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.