Wednesday, May 1, 2013

NSURL pathComponents example ios

Returns the individual path components of a file URL in an array.
- (NSArray *)pathComponents
Return Value of [NSURL pathComponents]
An array containing the individual path components of the URL.
Example of [NSURL pathComponents]
NSString *url_ = @"foo://;param?foo=1&baa=2#fragment";
NSURL *url = [NSURL URLWithString:url_];

NSLog(@"scheme: %@", [url scheme]); 
NSLog(@"host: %@", [url host]); 
NSLog(@"port: %@", [url port]);     
NSLog(@"path: %@", [url path]);     
NSLog(@"path components: %@", [url pathComponents]);        
NSLog(@"parameterString: %@", [url parameterString]);   
NSLog(@"query: %@", [url query]);       
NSLog(@"fragment: %@", [url fragment]);
Example of [NSURL pathComponents]
NSURL* url = [NSURL URLWithString:@""];
NSString* reducedUrl = [NSString stringWithFormat:
    [url.pathComponents objectAtIndex:1]];