SwiftData vs Core Data

The interviewer asks

“We're starting a new feature. Should we use SwiftData or Core Data, and what would make you pick Core Data in 2026?”

How to answer

For a new app or feature, SwiftData is the default: the schema lives in Swift, models are Observable, @Query drives SwiftUI, and @ModelActor plus Swift 6 checking keep concurrency honest. Core Data is still the right call when you need what SwiftData doesn't expose: store-level batch inserts and updates, custom merge policies, aggregate fetches, NSFetchedResultsController in UIKit while you support iOS 26 (ResultsObserver is iOS 27+), or CloudKit sharing and public databases. It isn't all-or-nothing: both use the same SQLite store format and can run side by side, so an existing Core Data app can adopt SwiftData screen by screen.

Key points

NeedSwiftDataCore Data
Schema@Model classes in Swift.xcdatamodeld + NSManagedObject subclasses
UI@Query (sectioned in iOS 27), ResultsObserver (iOS 27+)@FetchRequest, NSFetchedResultsController
Background work@ModelActor, compile-time isolationperform, runtime queue confinement
Batch operationsdelete(model:where:), enumerateNSBatchInsert/Update/DeleteRequest
ConflictsNo merge-policy APImergePolicy, query generations
CloudKitPrivate database onlyPrivate, shared and public (NSPersistentCloudKitContainer)
MigrationSchemaMigrationPlanStaged migration, mapping models
Uniqueness / indexes / history#Unique, #Index, fetchHistoryConstraints, fetch indexes, persistent history
Inheritance@Model subclasses (since iOS 26)Entity inheritance, abstract entities

If they dig deeper

SwiftData is younger and has sharper runtime edges: predicates that compile but fail in the store (computed properties, conditional casts), and, in my testing on the 27 runtime, .deny rules that didn't block a delete (Apple documents that they should) and R-tree indexes that rejected Double columns. Budget for tests against a real store. Core Data's API is older and less Swift-friendly, but it's 20 years mature, and its runtime behavior is well documented. Whatever you pick, hide it behind a Sendable repository protocol so features (and tests) don't depend on the framework, and switching or mixing later stays cheap. If you need full control of sync or must support non-Apple platforms, consider GRDB/SQLite with CKSyncEngine or your own backend instead.

Common pitfalls

Choosing Core Data for a new SwiftUI app "because SwiftData isn't ready" without naming a missing feature. Choosing SwiftData and discovering late that you need CloudKit sharing. Rewriting a working Core Data stack in one go instead of coexisting. Spreading @Query and ModelContext calls through business logic, which makes any later change of framework expensive.

How to use it

The same small repository on each framework; the app and tests only see NoteStore:

swift
import SwiftData

protocol NoteStore: Sendable {                               // what the app depends on
    func unreadCount() async throws -> Int
    func markAllRead() async throws
}

@ModelActor
actor SwiftDataNoteStore: NoteStore {
    func unreadCount() throws -> Int {
        try modelContext.fetchCount(FetchDescriptor<Note>(predicate: #Predicate { !$0.isRead }))
    }
    func markAllRead() throws {
        try modelContext.enumerate(FetchDescriptor<Note>(predicate: #Predicate { !$0.isRead })) {
            $0.isRead = true                                 // loads objects in batches
        }
        try modelContext.save()
    }
}
swift
import CoreData

final class CoreDataNoteStore: NoteStore {
    let container: NSPersistentContainer                     // Sendable
    init(container: NSPersistentContainer) { self.container = container }
    func unreadCount() async throws -> Int {
        let context = container.newBackgroundContext()
        return try await context.perform {
            let request = NSFetchRequest<NSManagedObject>(entityName: "Note")
            request.predicate = NSPredicate(format: "isRead == NO")
            return try context.count(for: request)
        }
    }
    func markAllRead() async throws {
        let context = container.newBackgroundContext()
        try await context.perform {
            let update = NSBatchUpdateRequest(entityName: "Note")  // store-level, no objects loaded
            update.predicate = NSPredicate(format: "isRead == NO")
            update.propertiesToUpdate = ["isRead": true]
            _ = try context.execute(update)
        }
    }
}

Note the trade-off in markAllRead: SwiftData walks the objects in batches, while Core Data's NSBatchUpdateRequest changes rows in SQLite without loading them (fast, but in-memory contexts must be told to refresh).

Best practices

  • Default to SwiftData for new code, and write down the specific feature if you pick Core Data
  • Check the deal-breakers early: CloudKit sharing or public data, very large batch updates, custom conflict handling
  • Coexist rather than rewrite: share the store, enable history, migrate feature by feature
  • Abstract persistence behind protocols injected through init
  • Test both stacks with in-memory stores and real migration fixtures

Related concepts