Last active
December 14, 2015 03:49
-
-
Save FGtatsuro/5023762 to your computer and use it in GitHub Desktop.
Confirm the behavior of NSRL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
int main(void) | |
{ | |
NSURL *baseWithSlash = [NSURL URLWithString:@"http://example.com/v1/"]; | |
NSURL *baseWithoutSlash = [NSURL URLWithString:@"http://example.com/v1"]; | |
NSString *relativeWithSlash = @"/foo"; | |
NSString *relativeWithoutSlash = @"foo"; | |
// 1.baseWithSlash + relativeWithSlash | |
NSURL *url = [NSURL URLWithString:relativeWithSlash relativeToURL:baseWithSlash]; | |
NSLog(@"%@", [url absoluteString]); | |
// 2.baseWithSlash + relativeWithoutSlash | |
url = [NSURL URLWithString:relativeWithoutSlash relativeToURL:baseWithSlash]; | |
NSLog(@"%@", [url absoluteString]); | |
// 3.baseWithoutSlash + relativeWithSlash | |
url = [NSURL URLWithString:relativeWithSlash relativeToURL:baseWithoutSlash]; | |
NSLog(@"%@", [url absoluteString]); | |
// 3.baseWithoutSlash + relativeWithoutSlash | |
url = [NSURL URLWithString:relativeWithoutSlash relativeToURL:baseWithoutSlash]; | |
NSLog(@"%@", [url absoluteString]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% clang NSURLTest.m -framework Foundation | |
% ./a.out | |
2013-02-24 22:10:39.211 a.out[28322:707] http://example.com/foo | |
2013-02-24 22:10:39.213 a.out[28322:707] http://example.com/v1/foo | |
2013-02-24 22:10:39.213 a.out[28322:707] http://example.com/foo | |
2013-02-24 22:10:39.214 a.out[28322:707] http://example.com/foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment