title: Objective-C: How to add query parameter to NSURL?
body: <p>Let's say I have an <code>NSURL</code>? Whether or not it already has an empty query string, how do I add one or more parameters to the <code>query</code> of the <code>NSURL</code>? I.e., does anyone know of an implementation of this function?</p>
  
  <pre><code>- (NSURL *)URLByAppendingQueryString:(NSString *)queryString
  </code></pre>
  
  <p>So that it satisfies this <code>NSURL+AdditionsSpec.h</code> file:</p>
  
  <pre><code>#import "NSURL+Additions.h"
  #import "Kiwi.h"
  
  SPEC_BEGIN(NSURL_AdditionsSpec)
  
  describe(@"NSURL+Additions", ^{
      __block NSURL *aURL;
  
      beforeEach(^{
          aURL = [[NSURL alloc] initWithString:@"http://www.example.com"];
          aURLWithQuery = [[NSURL alloc] initWithString:@"http://www.example.com?key=value"];
      });
  
      afterEach(^{
          [aURL release];
          [aURLWithQuery release];
      });
  
      describe(@"-URLByAppendingQueryString:", ^{
          it(@"adds to plain URL", ^{
              [[[[aURL URLByAppendingQueryString:@"key=value&amp;key2=value2"] query] should]
               equal:@"key=value&amp;key2=value2"];
          });
  
          it(@"appends to the existing query sting", ^{
              [[[[aURLWithQuery URLByAppendingQueryString:@"key2=value2&amp;key3=value3"] query] should]
               equal:@"key=value&amp;key2=value2&amp;key3=value3"];
          });
      });
  });
  
  SPEC_END
  </code></pre>