Reading and writing to files in Objective-C @techytube
Reading and writing to files 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

In Objective-C we can easily read and write text files by using the NSString class methods, and the way we do that is as follows:

NSString *fileContent = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

where url is the location of our actual file.



NSUTF8StringEncoding parameter is an Enum values specified by the system and it is widely used for .txt files.


To write strings/text to files we use the following syntax:
[newFileContent writeToURL:
url atomically:YES encoding:NSUTF8StringEncoding error:nil];

where newFileContent is an object of NSString class, "atomically:YES" means that the system will first create a temporary file, and if everything executes successfully, it will rename that to the file in our url.
Reading and writing to files in Objective-CWindows 8 Development - XAML OnLaunched / NetworkInformation ClassArrays in Objective-CInstalling MySQL On a Developer MachineFailover Clustering in Windows Server 2016Introduction to File Management in Objective-CWorking with UIAlertView class in iOSWindows 7 vs Windows 8 Setup Speed ComparisonRestoring database backups Differential and Transaction Log Backups, Part 4Windows 8 - Surviving the upgrade. the keyboard shortcuts to knowWorking with UIAlertViewDelegate protocol methods in iOS.NET 3.5/WPF Creating A Splash Screen
techytube |

Reading and writing to files in Objective-C

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER