Skip to content

Instantly share code, notes, and snippets.

@darkseed
Forked from stevestreza/NSURL+Pieces.h
Created September 26, 2011 21:23
Show Gist options
  • Save darkseed/1243439 to your computer and use it in GitHub Desktop.
Save darkseed/1243439 to your computer and use it in GitHub Desktop.
A method for debugging NSURLs to find where the different pieces of your URL are
#import <Foundation/Foundation.h>
@interface NSURL (Pieces)
-(NSDictionary *)piecesDictionary;
@end
#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