Tag Archives: NSURL

Objective-C – Convert NSString File Path to NSURL and Vice Versa

Convert NSString to NSURL

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
/* OR */
NSURL *fileURL = [NSURL fileURLWithPath:filePath];

 

Convert NSURL to NSString

// The output string will have the file:// prefix
NSString *filePath= [fileURL absoluteString];

// The output string will have the file path only
NSString *filePath= [fileURL path];

 

Updated @ 2011-01-10: Thanks for the comments of Brandon and Antal.