Core Data (Local Persistence)

June 02, 2026 1 min read

Core Data is Apple's framework for saving structured data locally and querying it efficiently.

The pieces

  • Entity — like a table (defined in the .xcdatamodeld editor).
  • Managed Object Context — the workspace where you create/edit/save objects.
  • Persistent Container — sets up the stack.
// Save
let note = Note(context: context)
note.title = "Hello"
try context.save()

// Fetch
let request: NSFetchRequest<Note> = Note.fetchRequest()
let notes = try context.fetch(request)
Tip: For simpler needs, UserDefaults stores small key/value settings; use Core Data (or SQLite) for real datasets.

Summary

Core Data persists structured data via entities and a managed context. Save and fetch through the context.