Monthly Archives: November 2013

NSURL Reference Chart

I work with NSURL from time to time and invariably need a chart to remind me what the class provides in the form of helpers. I tend to write something like the following to refresh my memory.

- (void)displayURLInfo:(NSURL *)url {
    NSLog(@"absoluteString: %@", url.absoluteString);
    NSLog(@"absoluteURL: %@", url.absoluteURL);
    NSLog(@"baseURL: %@", url.baseURL);
    NSLog(@"fileSystemRepresentation: %s", url.fileSystemRepresentation);
    NSLog(@"fragment: %@", url.fragment);
    NSLog(@"host: %@", url.host);
    NSLog(@"lastPathComponent: %@", url.lastPathComponent);
    NSLog(@"parameterString: %@", url.parameterString);
    NSLog(@"password: %@", url.password);
    NSLog(@"path: %@", url.path);
    NSLog(@"pathComponents: %@", url.pathComponents);
    NSLog(@"pathExtension: %@", url.pathExtension);
    NSLog(@"port: %@", url.port);
    NSLog(@"query: %@", url.query);
    NSLog(@"relativePath: %@", url.relativePath);
    NSLog(@"relativeString: %@", url.relativeString);
    NSLog(@"resourceSpecifier: %@", url.resourceSpecifier);
    NSLog(@"scheme: %@", url.scheme);
    NSLog(@"standardizedURL: %@", url.standardizedURL);
    NSLog(@"user: %@", url.user);
}

Here’s a couple of handy charts to help you decide which property to use.

File URLs (nulls removed)

NSURL PropertyFile Value
- (NSString *)absoluteStringfile:///Users/you/Library/Application%20Support/iPhone%20Simulator
/7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf
- (NSURL *)absoluteURLfile:///Users/you/Library/Application%20Support/iPhone%20Simulator
/7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf
- (const char *) fileSystemRepresentation/Users/you/Library/Application Support/iPhone Simulator
/7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf
- (NSString *)lastPathComponentMobileHIG.pdf
- (NSString *)path/Users/you/Library/Application Support/iPhone Simulator
/7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf
- (NSArray *)pathComponents(
"/",
Users,
you,
Library,
"Application Support",
"iPhone Simulator",
"7.0.3",
Applications,
GUID,
Library,
Content,
"MobileHIG.pdf"
)
- (NSString *)pathExtensionpdf
- (NSString *)relativePath/Users/you/Library/Application Support/iPhone Simulator
/7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf
- (NSString *)relativeStringfile:///Users/you/Library/Application%20Support/iPhone%20Simulator
/7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf
- (NSString *)resourceSpecifier/Users/you/Library/Application%20Support/iPhone%20Simulator
/7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf
- (NSString *)schemefile
- (NSURL *)standardizedURLfile:///Users/you/Library/Application%20Support/iPhone%20Simulator
/7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf

Internet URLs (nulls removed)

NSURL PropertyInternet Value
- (NSString *)absoluteStringhttp://blog.canispater.com:80/2013/11/nsurl-reference-chart/?pg=1&other=value
- (NSURL *)absoluteURLhttp://blog.canispater.com:80/2013/11/nsurl-reference-chart/?pg=1&other=value
- (NSString *)hostblog.canispater.com
- (NSString *)lastPathComponentnsurl-reference-chart
- (NSString *)path/2013/11/nsurl-reference-chart
- (NSArray *)pathComponents(
"/",
2013,
11,
"nsurl-reference-chart"
)
- (NSNumber *)port80
- (NSString *)querypg=1&other=value
- (NSString *)relativePath/2013/11/nsurl-reference-chart
- (NSString *)relativeStringhttp://blog.canispater.com:80/2013/11/nsurl-reference-chart/?pg=1&other=value
- (NSString *)resourceSpecifier//blog.canispater.com:80/2013/11/nsurl-reference-chart/?pg=1&other=value
- (NSString *)schemehttp
- (NSURL *)standardizedURLhttp://blog.canispater.com:80/2013/11/nsurl-reference-chart/?pg=1&other=value

Helpful? Anyone? Anyone?