Questions et réponses d'entretien les plus demandées et tests en ligne
Plateforme d'apprentissage pour la preparation aux entretiens, les tests en ligne, les tutoriels et la pratique en direct

Developpez vos competences grace a des parcours cibles, des tests blancs et un contenu pret pour l'entretien.

WithoutBook rassemble des questions d'entretien par sujet, des tests pratiques en ligne, des tutoriels et des guides de comparaison dans un espace d'apprentissage reactif.

Chapter 8

Persistence with UserDefaults, Files, Codable, Core Data, SwiftData, and Keychain

Store app data correctly by learning which storage option fits which problem, from tiny settings to offline domain models and secure credentials.

Inside this chapter

  1. Choosing the Right Persistence Tool
  2. UserDefaults for Simple Preferences
  3. Files and Codable
  4. Core Data and SwiftData
  5. Keychain for Sensitive Information
  6. Offline-First Thinking

Series navigation

Study the chapters in order for the clearest path from setup and Swift basics to architecture, release management, and advanced iOS engineering. Use the navigation at the bottom to move smoothly across the full tutorial series.

Tutorial Home

Chapter 8

Choosing the Right Persistence Tool

Not all data should be stored in the same way. Small preferences, large documents, cached API responses, user profiles, secure tokens, and relational business data each have different storage needs. Good persistence design begins with the question: what kind of data is this?

Chapter 8

UserDefaults for Simple Preferences

UserDefaults.standard.set(true, forKey: "hasSeenOnboarding")
let seen = UserDefaults.standard.bool(forKey: "hasSeenOnboarding")

UserDefaults is appropriate for tiny configuration flags and preferences. It is not a general-purpose database and should not hold large structured domain models.

Chapter 8

Files and Codable

struct DraftNote: Codable {
    let title: String
    let body: String
}

let encoder = JSONEncoder()
let data = try encoder.encode(DraftNote(title: "Trip", body: "Book hotel"))

File-based persistence is useful for exported reports, cached payloads, drafts, offline reference content, and media-related workflows.

Chapter 8

Core Data and SwiftData

Core Data is a mature object graph and persistence framework used heavily in iOS applications. SwiftData is a modern layer that simplifies parts of model persistence for newer SwiftUI-oriented codebases. Students should understand concepts such as entities, relationships, fetches, context changes, migrations, and performance implications.

Real examples include offline shopping carts, note-taking apps, CRM field records, health logs, and saved article libraries.

Chapter 8

Keychain for Sensitive Information

Authentication tokens, refresh secrets, and highly sensitive credentials should go in Keychain, not in plain files or UserDefaults. Security architecture matters because mobile devices can be lost, shared, or inspected.

Chapter 8

Offline-First Thinking

A strong iOS app should keep the user productive even during poor connectivity. Persistence is not just about saving data. It is also about modeling sync boundaries, conflict resolution, stale cache detection, and user trust.

Copyright © 2026, WithoutBook.