Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UrlByAppendingPathComponent vs UrlByAppendingPathExtension

I've read the documentation, and it looks like some edge cases might be different (trailing slashes, etc.), but it's not clear to me what the main difference between these two method is. Do the terms Component and Extension have special meaning in the URL world that people other than me understand?

like image 633
Greg Smalter Avatar asked May 01 '12 21:05

Greg Smalter


1 Answers

The path extension is for adding things like .html to the URL, and the path component is for adding things like /news/local. The documentation for path extension:

If the original URL ends with one or more forward slashes, these are removed from the returned URL. A period is inserted between the two parts of the new URL.

So http://hello.com/news/ would become http://hello.com/news.html

The docs for path component:

If the original URL does not end with a forward slash and pathComponent does not begin with a forward slash, a forward slash is inserted between the two parts of the returned URL, unless the original URL is the empty string.

So http://hello.com/news/ would become http://hello.com/news/html

Here's a quick test:

NSURL *originalURL = [NSURL URLWithString:@"http://hello.com/news"];
NSLog(@"%@", [originalURL URLByAppendingPathComponent:@"local"]);
NSLog(@"%@", [originalURL URLByAppendingPathExtension:@"local"]);

Output:

http://hello.com/news/local
http://hello.com/news.local
like image 198
nevan king Avatar answered Oct 27 '22 00:10

nevan king