Skip to content

Instantly share code, notes, and snippets.

@eienf
Created August 19, 2012 07:24
Show Gist options
  • Save eienf/3393223 to your computer and use it in GitHub Desktop.
Save eienf/3393223 to your computer and use it in GitHub Desktop.
check what is what of NSURL properties.
#import <Foundation/Foundation.h>
NSDictionary *dictionaryForURL(NSURL *aURL)
{
NSLog(@"scheme = %@ host = %@ port = %@ fragment = %@ lastPathComponent = %@ parameterString = %@ "
@"query = %@ user = %@ password = %@ resourceSpecifier = %@",
[aURL scheme],[aURL host],[aURL port],[aURL fragment],[aURL lastPathComponent],[aURL parameterString],
[aURL query],[aURL user],[aURL password],[aURL resourceSpecifier]);
NSLog(@"absoluteString = %@",[aURL absoluteString]);
NSLog(@"relativePath = %@",[aURL relativePath]);
NSLog(@"relativeString = %@",[aURL relativeString]);
NSLog(@"path = %@",[aURL path]);
NSLog(@"pathExtension = %@",[aURL pathExtension]);
NSLog(@"baseURL = %@",[aURL baseURL]);
NSLog(@"standardizedURL = %@",[aURL standardizedURL]);
NSLog(@"absoluteURL = %@",[aURL absoluteURL]);
NSMutableDictionary *aDict = [NSMutableDictionary dictionary];
for (NSString *aString in [[aURL query] componentsSeparatedByString:@"&"]) {
NSArray *anArray = [aString componentsSeparatedByString:@"="];
NSString *aKey = [anArray objectAtIndex:0];
if ( [anArray count] == 2 ) {
NSString *aValue = [anArray objectAtIndex:1];
[aDict setObject:aValue forKey:aKey];
}
else {
[aDict setObject:[NSNull null] forKey:aKey];
}
}
return aDict;
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSLog(@"%@",dictionaryForURL([NSURL URLWithString:@"myscheme://myname:hogehoge@localhost:8080/cgi-bin/time.cgi;options?from=123456&to=789012&wrap=YES&novalue#something"]));
// <scheme>://<user>:<password>@<host>:<port>/<path>;<parameterString>&<query>#<fragment>
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment