> For the complete documentation index, see [llms.txt](https://ios-course.cornellappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ios-course.cornellappdev.com/resources/archived-past-semesters/2019/persistance.md).

# Persistence: UserDefaults

## What is Persistence?

In short, **data persistence** is keeping the data you are working with around. This means that the same data can be retrieved without being altered when the user closes and then re-opens the app.

### Achieving Persistence in iOS

There are several ways to achieve persistence in iOS, including:

1. UserDefaults
2. CoreData
3. CloudKit
4. UIDocument

In the course, we focus on `UserDefaults`, which is used to achieve lightweight persistence, e.g. to store small amounts of data. &#x20;

#### Lecture Slides

{% file src="/files/-M6\_JhxpcG2HdLmbS\_GR" %}
Lecture Slides
{% endfile %}

## Lecture Demos

Persistence has been an additional topic for a few different semesters, so there's a few demos available!

### Spring 2020 Demo

The following demo introduces `SnapKit` alongside using `UserDefaults`!

{% file src="/files/-M6\_Jt2pBOD8FZWXMySy" %}
Demo Starter Code
{% endfile %}

{% file src="/files/-M6\_Jw9Qqw-rqkzzcj5S" %}
Completed Demo Code
{% endfile %}

### Spring 2019 Demo

The following demo involves using `UserDefaults` with custom classes by conforming the class to `Codable`.&#x20;

{% file src="/files/-M-Ij2\_r2X0vaKH43Y-d" %}
Demo Starter Code
{% endfile %}

{% file src="/files/-M-Ij6wpHO9x7ZQHDdJl" %}
Completed Demo Code
{% endfile %}

### Fall 2019 Demo

The following demo introduces `SnapKit` alongside using `UserDefaults`!

{% file src="/files/-M-IjHJzOS\_8cLd8n\_fE" %}
Demo Starter Code
{% endfile %}

{% file src="/files/-M-IjKgBbIBJ6ESp3dWH" %}
Completed Demo Code
{% endfile %}
