Saving Data in iOS

May 31 2022 · Swift 5.5, iOS 15, Xcode 13

Part 1: Files & Data

03. Paths

Episode complete

Play next episode

About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 02. Documents Directory URL Next episode: 04. Challenge: URLs

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 03. Paths

This course was originally recorded in April 2020. It has been reviewed and all content and materials updated as of November 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

The string components of a URL, are collectively known as its path. By acting as a wrap around a string, a URL makes it really easy to manipulate that string for what you need. Please join me in the paths start playground. From this point on, the playground in each video, is going to start off with the last one ended. Except perhaps for a little bit of cleanup and organization. You might have looked over to the right, at your sidebar, and wonder what all that gibberish is about. If you guessed that it's the path of the documentDirectory for the playground, you'd be right, but as this property is a URL, its QuickLook just shows a folder. Not too informative. If you want to see a URLs path, you can just use its path property. A URLs path is a string which is more informative in a playground. But the documentDirectory path is always going to be very long and hard to read. It will also be different for every playground and for every iOS app. What you're looking at here, is not something you'd want to memorize. So, you'll ask File Manager for the right path. As you saw at the end of the last video, one nice thing about URLs versus strings is that you can right-click them to open them in Finder. To start off with, a playground's documentDirectory is completely empty. Let's create some file URL so you can remedy that. Start by deleting all the code in your playground. Then, add a constant called Reminders Data URL. Use the URL initializer that has the argument labels, follow your URL with path, and relativeTo. The path here is the name of the file, go with reminders, and it'll be relative to the documentDirectory URL. Another way of saying that we'll put it in the documents folder. Along with the Reminders Data, you're also going to save a string. Do that at string URL. This time you're constructed not with a URL initializer but a couple of instant methods that return modified URLs. appendingPathComponent allows you to add a file name to a directory. That doesn't seem kind of thing as the initializer above. I just wanted to introduce you to both APIs, so, you're aware of the different options available. Like in the previous initializer, notice that you're not using a forward slash in the string in order to represent a path separator. That's taken care of for you. The same is true of the dot. When you use appendingPathExtension with TXT in this case. Let's check out the path. It contains a forward slash and string dot TXT at the end, as expected.