Let's take a base URL:
NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"];
Now:
[NSURL URLWithString:@"foo" relativeToURL:baseURL];
// Will give us http://example.com/v1/foo
[NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL];
// -> http://example.com/v1/foo?bar=baz
[NSURL URLWithString:@"/foo" relativeToURL:baseURL];
// -> http://example.com/foo
[NSURL URLWithString:@"foo/" relativeToURL:baseURL];
// -> http://example.com/v1/foo
[NSURL URLWithString:@"/foo/" relativeToURL:baseURL];
// -> http://example.com/foo/
[NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL];
// -> http://example2.com/
NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"];
Now:
[NSURL URLWithString:@"foo" relativeToURL:baseURL];
// Will give us http://example.com/v1/foo
[NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL];
// -> http://example.com/v1/foo?bar=baz
[NSURL URLWithString:@"/foo" relativeToURL:baseURL];
// -> http://example.com/foo
[NSURL URLWithString:@"foo/" relativeToURL:baseURL];
// -> http://example.com/v1/foo
[NSURL URLWithString:@"/foo/" relativeToURL:baseURL];
// -> http://example.com/foo/
[NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL];
// -> http://example2.com/