Saving Data in iOS

Find out where and how to save data in iOS! This course explores common methods for persisting user data, all from within Xcode Playgrounds. By Felipe Laso-Marsetti.

4.1 (8) · 2 Reviews

Download materials
Save for later
Comments
Share

Learning path

This is part of the iOS Data & Networking learning path. View path.

Who is this for?

Beginner to intermediate developers. If you’re a beginner developer, or if you are following our iOS learning paths, this course will teach you the foundations of saving and loading data in iOS.

This course is also a great guide for intermediate developers who would like to know more about how to work with data, files, the filesystem, and parsing data to/from JSON or Property Lists.

Covered concepts

  • Data: basic concepts
  • Available data types in Swift
  • Files & the Filesystem
  • The app bundle
  • The app sandbox
  • FileManager, URL, and Foundation Data
  • JSON and Property lists formats for storing and serializing data with the Encodable and Decodable protocols
  • How to load and save data in a real-world SwiftUI application

Part 1: Files & Data

01
Toggle description

Welcome to the Saving Data in iOS course! Find out what you’ll learn, including FileManager, the Filesystem, URLs, Foundation Data and data types, and how to save and load data using files.

Toggle description

Familiarize yourself with FileManager and how to use it to retrieve the URL for the existing Document directory.

Paths 4:09
Toggle description

Learn how to add to a URL’s paths, and customize the files and filenames you use to save data with the URL you acquire.

Toggle description

Practice working with strings and URLs to create a path and filename where data would get stored to.

Toggle description

Learn about Foundation Data and the term “Data”. Also, famirialize yourself with the basics of Swift data types and structures like Integers, Floats, Doubles, Strings, Dictionaries, Sets, and Arrays.

Toggle description

Save and load data from an array into a binary file (without an extension), as well as a file with the .txt extension.

String 3:46
Toggle description

Save an array of integers, representing emoji, and also a string to file. Also, see how you’re saving emoji to a text file both as bytes of data, or as string data.

Toggle description

Try to save a string to a file and read it back, this way you’ll understand what happens behind the scenes when you use the “write” method on String.

Conclusion 0:57
Toggle description

TYou can now work with the FileManager, the Filesystem, and Data in order to save and load data from files in your app. In this episode, find out what’s next!

Part 2: JSON

Toggle description

Let’s review what you’ll be learning in this part of the course, including JSON, its structure and types, saving and loading data using JSON, and Swift’s Codable protocol.

Toggle description

Get an overview of JSON, what it means, the data format, and supported data types. Then, learn how to load, or decode, data from a JSON file.

Toggle description

Try to use the knowledge from the previous video to now load, or decode via JSONDecoder, an array of JSON data.

Toggle description

In this episode, find out how to save files on a simulator or physical iOS device. Also, learn about the app bundle.

Toggle description

Save your JSON data to disk. This will mean the app is now loading and saving its data to the app bundle

Toggle description

This challenge asks you to handle encoding an array of JSON data to a file, as opposed to encoding a single item.

Toggle description

Get a sense of how to encode/decode codable objects within each other. Also learn about CodingKeys and how to handle mapping different JSON properties to your Swift ones.

Conclusion 0:53
Toggle description

Let’s review where you are with your JSON data-saving core concepts, and discuss what’s next.

Part 3: Property Lists

Toggle description

This part of the course includes learning about Property Lists, how they compare to JSON, and saving and loading data via PList files.

Toggle description

Cover the basics of Property Lists, .plist files, their difference with JSON, and the data types you can store in them.

Toggle description

Take on a challenge to see if you can save your existing JSON data into a property list file instead.

Toggle description

A back to back challenge where you attempt to now read back the property list file you saved in the previous video.

Toggle description

Learn about the differences of working with JSON and Property Lists, pros and cons of each, and when you’d want to consider using them.

Conclusion 2:25
Toggle description

Congrats on finishing the course! Where can you take your skills now? Learn about next steps and further resources.

Up next

iOS & Swift
Beginning Networking with URLSession
Learn how to use URLSession, Apple’s networking API, including how to download data, show download progres... more

Instructors

Contributors

Over 300 content creators. Join our team.