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 Property | File Value |
---|---|
- (NSString *)absoluteString | file:///Users/you/Library/Application%20Support/iPhone%20Simulator /7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf |
- (NSURL *)absoluteURL | file:///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 *)lastPathComponent | MobileHIG.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 *)pathExtension | |
- (NSString *)relativePath | /Users/you/Library/Application Support/iPhone Simulator /7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf |
- (NSString *)relativeString | file:///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 *)scheme | file |
- (NSURL *)standardizedURL | file:///Users/you/Library/Application%20Support/iPhone%20Simulator /7.0.3/Applications/GUID/Library/Content/MobileHIG.pdf |
Internet URLs (nulls removed)
NSURL Property | Internet Value |
---|---|
- (NSString *)absoluteString | http://blog.canispater.com:80/2013/11/nsurl-reference-chart/?pg=1&other=value |
- (NSURL *)absoluteURL | http://blog.canispater.com:80/2013/11/nsurl-reference-chart/?pg=1&other=value |
- (NSString *)host | blog.canispater.com |
- (NSString *)lastPathComponent | nsurl-reference-chart |
- (NSString *)path | /2013/11/nsurl-reference-chart |
- (NSArray *)pathComponents | ( "/", 2013, 11, "nsurl-reference-chart" ) |
- (NSNumber *)port | 80 |
- (NSString *)query | pg=1&other=value |
- (NSString *)relativePath | /2013/11/nsurl-reference-chart |
- (NSString *)relativeString | http://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 *)scheme | http |
- (NSURL *)standardizedURL | http://blog.canispater.com:80/2013/11/nsurl-reference-chart/?pg=1&other=value |
Helpful? Anyone? Anyone?