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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With