From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Read and write text files

Read and write text files

- [Instructor] In iOS, one of the simplest forms of persistent data and the basis for many file formats is the text file. I'm going to show you one simple way to set up text files. I'll be making our demo in Swift Playgrounds based on a starter file I created called ReadWriteText. If it starts to run, hold down the Play button and select Manually Run and then stop it. There's two parts to reading and writing a text file: getting a file's name and then reading or writing the file. For file names, you can use either a string of the complete file path or a URL. You'll find the URL is a lot more flexible in use. I'll get the URL for the document directory of the app using a computed property I started here. We'll make this URL using the FileManager class, which controls the file system. It has a singleton, Default, to point to the default file system. Add a dot after that and type url, and you'll see a few more methods. Select the method url(for: FileManager.SearchPattern for: URL?…

Contents