• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSURL relativePath problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURL relativePath problem


  • Subject: Re: NSURL relativePath problem
  • From: Kyle Sluder <email@hidden>
  • Date: Thu, 29 Aug 2013 11:20:28 -0700

On Thu, Aug 29, 2013, at 11:02 AM, Koen van der Drift wrote:
> I'm having some difficulties constructing a URL from a baseURL and a
> relativeURL when the relativeURL starts with a question mark:
>
>     NSURL *baseURL = [NSURL URLWithString: @"http://www.test.com/test/";];
>     NSString *relativeString = @"?query=test";
>
>     NSURL *url = [NSURL URLWithString: relativeString relativeToURL:
>     baseURL];
>
> This results in the following url:
>
> ?query=test -- http://www.test.com/test/
>
> While I want it to be:
>
> http://www.test.com/test/?query=test
>
>
> I can just generate the whole URL at once, but I was wondering why I get
> this behavior?

You're looking at the output of -[NSURL description], which remembers
whether the URL was created as an absolute or relative URL and prints
itself accordingly.

If you send -absoluteString to the URL, you'll find that it produces the
correct output:

% python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on
darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Foundation
>>> Foundation.NSURL.URLWithString_relativeToURL_('?query=test', Foundation.NSURL.URLWithString_('http://www.test.com/test/'))
?query=test -- http://www.test.com/test/
>>> relURL=_
>>> relURL.absoluteString()
u'http://www.test.com/test/?query=test'

--Kyle Sluder
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSURL relativePath problem
      • From: Koen van der Drift <email@hidden>
References: 
 >NSURL relativePath problem (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Re: NSURL relativePath problem
  • Next by Date: Re: NSURL relativePath problem
  • Previous by thread: Re: NSURL relativePath problem
  • Next by thread: Re: NSURL relativePath problem
  • Index(es):
    • Date
    • Thread