Created
September 26, 2011 19:52
-
-
Save stevestreza/1243216 to your computer and use it in GitHub Desktop.
A method for debugging NSURLs to find where the different pieces of your URL are
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> | |
@interface NSURL (Pieces) | |
-(NSDictionary *)piecesDictionary; | |
@end |
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 "NSURL+Pieces.h" | |
@implementation NSURL (Pieces) | |
-(NSDictionary *)piecesDictionary{ | |
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; | |
#define AddValueForSelector(__selector) do{ id obj = [self performSelector:NSSelectorFromString(__selector)]; if(obj) [dictionary setObject:obj forKey:__selector]; }while(0) | |
AddValueForSelector(@"absoluteString"); | |
AddValueForSelector(@"absoluteURL"); | |
AddValueForSelector(@"baseURL"); | |
AddValueForSelector(@"fragment"); | |
AddValueForSelector(@"host"); | |
AddValueForSelector(@"lastPathComponent"); | |
AddValueForSelector(@"parameterString"); | |
AddValueForSelector(@"password"); | |
AddValueForSelector(@"path"); | |
AddValueForSelector(@"pathComponents"); | |
AddValueForSelector(@"pathExtension"); | |
AddValueForSelector(@"port"); | |
AddValueForSelector(@"query"); | |
AddValueForSelector(@"relativePath"); | |
AddValueForSelector(@"relativeString"); | |
AddValueForSelector(@"resourceSpecifier"); | |
AddValueForSelector(@"scheme"); | |
AddValueForSelector(@"standardizedURL"); | |
AddValueForSelector(@"user"); | |
#undef AddValueForSelector | |
return dictionary; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output by NSLogging this call for "http://apple.com/imac/":
{ absoluteString = "http://apple.com/imac/"; absoluteURL = "http://apple.com/imac/"; host = "apple.com"; lastPathComponent = imac; path = "/imac"; pathComponents = ( "/", imac ); pathExtension = ""; relativePath = "/imac"; relativeString = "http://apple.com/imac/"; resourceSpecifier = "//apple.com/imac/"; scheme = http; standardizedURL = "http://apple.com/imac/"; }