Working with paths and urls in Objective-C @techytube
Working with paths and urls in Objective-C  @techytube
Uploaded September 2012 | Updated September 2026, 2 weeks ago
Subscribe to our channel here for notifications on new video trainings. For more videos on technology, visit our website at http://www.techytube.com.
By pavel@techytube, for more from this author visit:
techytube.com/author/pavel

When working with files in Objective-C, we can specify the paths to them as follows:

NSString *path = @"/Users/pavel/file.txt";



However, the recommended way (by Apple engineers) to specify that is by using URL-s (Uniform Resource Locator).

The iOS SDK class that provides us urls manipulation is named NSURL, and it has a lot of class convenience methods that make developers' lives easier.
To create a NSURL object, we use the syntax:

NSURL *url = [NSURL URLWithString:@"file:///Users/pavel/file.txt"];


Note that the way we specify the string is different from in "path" cases.
It should always have the "file" schema in front of it, than a colon, and 3 slashes.


If we want to create a NSURL object, providing a string as in path cases, we can use a NSURL method which allows us to do that:

NSURL *newUrl = [NSURL fileURLWithPath:@"/Users/pavel/Public/file.txt"];



To move files from one location to another using urls instead of paths, we should use:

[[NSFileManager defaultManager] moveItemAtURL:url toURL:newUrl error:nil];
Working with paths and urls in Objective-CTaking in command-line arguments in a .NET console applicationWorking with IBOutlet properties in XcodeHow to use the UIImageView class to animate a series of imagesMicrosoft SQL Server 2012 Always on Part 2 of 3How to create view controllers programmatically in iOSSonicWall - How to allow or block access to a specific websiteDifferent types of UITableView cells in iOSLinux Archive, Backup And Compress Utility (tar, Gzip, Bzip2, 7zip, Zip etc.) Part - 2
techytube |

Working with paths and urls in Objective-C

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER