Saving Data

Most of the time you need to store at least a few small details about your user, like a name, a password, a session token or a Boolean value about a fired tutorial screen. While other times you need to maintain a whole bunch of data in a complex database, or just save same draft images to the disk.

Saving Data to Shared User Defaults

The simplest way to save non-critical user data is to store in the user defaults. It’s just like a dictionary, a static collection of key-value pairs. Have you ever find some hidden toggles for an iOS app in the settings? Those values are also stored here for sure.

Saving Data to Keychain

Sometimes you have to store critical user information, most likely a password. Then it’s time to use the built-in keychain for that, but don’t forget to save yourself some headache and use one of the nice wrappers over there.

Saving Data in Files

Sometimes it’s easier to save to a file, like caching images for faster reloading, or saving a big, complex data structure of a game. Compared to Android, you can only save to your sandbox folder by default, which is not accessible by other applications.

Saving Data to Core Databases

A lot of the times you have to save and gather complex relational structures in your application, in this case you have to plan and build a database. Core Data is Apple’s database solution built on top of an SQLite database.

8 Curated Resources

There are different ways to enable communication between view controllers. But are they all good?

User Defaults

free, Tutorial

Example code for saving and reading the user defaults with some details and the list of supported types you can use.

Secure iOS User Data

free, Tutorial

Well written tutorial about the basic requirements you have to do to secure user data.

Tutorial on Writing Saving to and Reading from a text file in Swift.

A complete tutorial with nice illustrations to start a basic Core Data application. Example code can be downloaded at the bottom.

Core Data by Tutorials

, E-Book

Intermediate level book with the basics like setting up your own Core Data Stack all the way to advanced topics like migration, performance, multithreading, and more!

An Objective-C tutorial about sharing data using App Groups.

Create App Group to share data

, Video Course

Sharing data between apps and extensions is not a complex process, but there are several steps involved. See how to create app groups for data sharing in this video.