NSString's stringByAppendingPathComponent: removes a '/' in http://
Posted
by Jasarien
on Stack Overflow
See other posts from Stack Overflow
or by Jasarien
Published on 2010-04-05T16:35:11Z
Indexed on
2010/04/05
17:03 UTC
Read the original article
Hit count: 402
I've been modifying some code to work between Mac OS X and iPhone OS.
I came across some code that was using NSURL
's URLByAppendingPathComponent:
(added in 10.6), which as some may know, isn't available in the iPhone SDK.
My solution to make this code work between OS's is to use
NSString *urlString = [myURL absoluteString];
urlString = [urlString stringByAppendingPathComponent:@"helloworld"];
myURL = [NSURL urlWithString:urlString];
The problem with this is that NSString
's stringByAppendingPathComponent:
seems to remove one of the /'s from the http:// part of the URL.
Is this intended behaviour or a bug?
Edit
Ok, So I was a bit too quick in asking the question above. I re-read the documentation and it does say:
Note that this method only works with file paths (not, for example, string representations of URLs)
However, it doesn't give any pointers in the right direction for what to do if you need to append a path component to a URL on the iPhone...
I could always just do it manually, adding a /if necessary and the extra string, but I was looking to keep it as close to the original Mac OS X code as possible...
© Stack Overflow or respective owner