Saving Data in iOS

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

Part 1: Files & Data

01. Introduction

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

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

Notes: 01. Introduction

Prerequisite knowledge for this course assumes familiarity with Swift, and being comfortable building a SwiftUI application in Xcode.

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

Transcript: 01. Introduction Hi everyone, I'm Jessy. I work with Felipe, who is the instructor of this course. He originally recorded this using the tooling that was available in April, 2020. Now, I've gone through the whole course myself in November, 2021 with the latest version of Xcode and Swift. And it's still in perfectly working condition. This aspect of iOS development has become quite stable. So, this will be the last you'll be seeing of me in this course, but I hope that you'll join me for some of the other courses I've created later in our learning parts. And now here's the fantastic Felipe. Hi friends, it's Felipe. Whereas my friends and relatives now call me, forgetful Felipe. Welcome to the saving data in iOS course, where you'll learn about saving data and working with data that has been saved. Recently I'm always leaving the house but I'm forgetting something, my keys, my sunglasses, my wallet, I can never seem to remember to take them all with me. I have been trying to use my brain to save what I need to take every time I go out but it's clearly not working. If you're coming over from building your awesome reminders app, you've noticed it too has a problem of forgetting things between app launches. How about we tackle both of our problems in this course? You'll store or persist as it can also be referred to your reminder's data, and I'll then have a great tool to not forget things. Let's go over the contents of this course. You'll learn about what data is, some basic concepts and data types, files, the file system and the app bundle, file manager, URLs and foundation data, JSON and property lists. For the first part of this course, you won't be using an Xcode project or building to iOS devices or the simulator. Instead, you'll be working in playgrounds which are a great way to learn most of the concepts you'll then use in the latter parts of this course. At the end of this part, you will learn how to save and load data, techniques that you will then transfer in parts two and three of the course. When you use your newfound knowledge to store or persist your reminders in an iOS application. Byte use to represent data and it's different types. If you're not that familiar with bytes they're made above eight bits. A a bit is short for binary digit, something we could think of as zero or one. When an amount of data gets measured that's done using bytes. You can't directly quantify your data without a unit, like gigabyte or terabyte. It wouldn't mean anything to say, I'm going to save a million data today in my app. That's because data in common use is what's known as a mass noun or uncountable noun. It is the plural form of the word datum, but you'll probably never come across that form when developing apps. You can have some data or a piece of data. One last note, you can also correctly pronounce data as data if you prefer. In iOS bytes of data can be stored in the foundation frameworks data structure which will be covered in this course. What your data represents is also important. A PDF, a text file and an image are all files with data, but the way in which they are arranged is what differentiates them. They are also made up of more basic data types that together create a more complex and robust object. Some of the data types you will use in this course and in your applications are integers to represent whole numbers. Floating points to represent decimal numbers. Doubles which also represent decimal numbers but with higher precision basically bigger numbers. Strings, which store text. And Booleans to store true or false. The terms saving is interchangeable with persistence. When you close an app and open it again at a later point if the data you were working with was saved and without a problem, it will persist and still be available. Persisting data involves serializing it, which is a transformation from an in-memory representation of that data to something more appropriate for storage. You don't just take a Swift data structure and save it directly, there's some metamorphosis involved. The phrase saving to disk is used extensively for writing the results of serialization to your devices flash memory, even in Apple's own documentation. But there has never been a single iOS device equipped with a physical disk, like the original iPod had. So technically the term saving to drive is more accurate. But spinning platter hard disks were a main state of the industry for so long, the term disk itself has persisted. You can even see this when your SSD equip Mac has its own main drive named Macintosh HD. Before embarking upon your data saving journey in this course, you should have a good understanding of the Swift programming language. If you feel lost when watching the next few videos, we've got a course on Swift that might help you out. If you can get comfortable with the material in the programming in Swift course, you should be ready to tackle this one. In this first part of the course, you'll get comfortable with files and the file manager. Your serialized data will be stored in files within your devices file system and you'll need to manage them. Their locations will be represented with URLs. Swift has a handy URL type. Then you'll get into the details of how your bytes of data get represented in Swift. You'll be converting back and forth from that binary data and other Swift types. That's it for the introduction. Please join me in the next video. There, you'll be making the necessary preparations to start saving data, see you there.