The problem
You have a Core Data app with years of user data in a SQLite store. SwiftData promises less code, @Query, and Swift concurrency that the compiler checks. The risk is the store: get the mapping wrong and SwiftData treats the existing file as a different schema, migrates it, and data disappears. SwiftData is built on Core Data’s storage, so your data can stay exactly where it is. This guide covers the two ways to move, full adoption and coexistence, the type mapping, and the cases where moving is the wrong call.
SwiftData needs iOS 17. If you still support iOS 16, coexistence is the only option, and only for code that runs on 17 and later.
Decide: full move, coexistence, or stay
Apple’s WWDC23 session Migrate to SwiftData describes two routes:
- Full adoption. Replace the Core Data stack and model file with SwiftData models that describe the same entities. The store file stays.
- Coexistence. Keep the Core Data stack and add a SwiftData stack that reads and writes the same store. Apple suggests it when you need to keep older OS support or cannot convert everything at once.
Apple’s Adopting SwiftData for a Core Data app sample ships three versions of one app: pure Core Data, full SwiftData, and a coexistence version where the main app stays on Core Data and a widget uses SwiftData. Download it before you start. It is the clearest reference for both setups.
Step 1: generate or write matching models
In the model editor, Editor > Create SwiftData Code generates @Model classes from your .xcdatamodeld. Treat the result as a draft. The session’s rule is that each entity needs a SwiftData type with the same entity name and the same properties. The class name becomes the entity name, so a Core Data entity called Trip needs @Model final class Trip.
import Foundation
import SwiftData
@Model
final class Trip {
var name: String = ""
var destination: String = ""
var startDate: Date = Date.now
var endDate: Date = Date.now
@Relationship(deleteRule: .cascade, inverse: \BucketListItem.trip)
var bucketList: [BucketListItem] = []
init(name: String, destination: String, startDate: Date, endDate: Date) {
self.name = name
self.destination = destination
self.startDate = startDate
self.endDate = endDate
}
}
@Model
final class BucketListItem {
var title: String = ""
var isDone: Bool = false
var trip: Trip?
init(title: String) { self.title = title }
}
If a Swift property name should differ from the stored attribute, keep the stored name with @Attribute(originalName: "start_date") instead of renaming the column.
Map the types
| Core Data | SwiftData | Notes |
|---|---|---|
| String, Boolean, Date, UUID | String, Bool, Date, UUID |
Direct |
| Integer 16 / 32 / 64 | Int16, Int32, Int64 or Int |
Match the width you stored |
| Double, Float, Decimal | Double, Float, Decimal |
Direct |
| URI | URL |
Direct |
| Binary Data with external storage | Data with @Attribute(.externalStorage) |
Keep the option or the blobs move inline |
| Transformable | @Attribute(.transformable(by:)) with your transformer, or a Codable type |
Reuse the same transformer name for existing data |
| To-one relationship | Optional model property | |
| To-many relationship | Array of models | No ordered relationships; add a sort key |
| Optional attribute | Optional Swift property | Optionality must match |
Fatbobman’s Reinventing Core Data Development with SwiftData Principles explains why the mapping deserves care. Core Data lets you choose the underlying type and control conversions yourself; SwiftData decides for you. An enum or an optional number that you stored by hand in Core Data may not line up with how SwiftData would store the same Swift type. Inspect what is actually in the store before deciding.
Version it from day one
Make these models your first VersionedSchema, even though nothing has changed yet. The session points to versioned schemas so SwiftData can evaluate differences later, and every future model change needs a starting point.
Step 2: reuse the store file
SwiftData’s default store is default.store in Application Support. Your Core Data store is wherever NSPersistentContainer put it, usually <ModelName>.sqlite in the same folder. Point SwiftData at the existing file:
import Foundation
import SwiftData
enum Persistence {
static var storeURL: URL {
URL.applicationSupportDirectory.appending(path: "Trips.sqlite")
}
static func makeContainer() throws -> ModelContainer {
let configuration = ModelConfiguration(url: storeURL)
return try ModelContainer(
for: Trip.self, BucketListItem.self,
configurations: configuration
)
}
}
If the store lives in an App Group container, build the URL from FileManager.default.containerURL(forSecurityApplicationGroupIdentifier:). Apple’s sample notes a related behavior: for an app with the App Groups entitlement, SwiftData’s default location is the root of the group container, and it copies an existing store there when an app gains a group. Be explicit about the URL so neither framework guesses.
Then delete the Core Data stack and the model file, attach the container with .modelContainer(_:), and replace fetch requests with @Query and FetchDescriptor. Saving changes too: the main context autosaves, so most explicit save() calls in view code can go.
Step 3, if you need it: coexistence
Coexistence means two stacks on one file. Apple’s session and sample agree on three rules.
Same store URL. Set the Core Data store description’s URL to the file SwiftData opens.
Persistent history on in Core Data. SwiftData turns it on automatically, Core Data does not. The session warns that without it, the store opens read-only.
Different class names, same entity names. Rename the Core Data classes, for example to CDTrip, while the entity stays Trip.
import CoreData
final class CoreDataStack {
let container: NSPersistentContainer
init(storeURL: URL) {
container = NSPersistentContainer(name: "Trips")
if let description = container.persistentStoreDescriptions.first {
description.url = storeURL
description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
}
container.loadPersistentStores { _, error in
if let error { preconditionFailure("Store failed to load: \(error)") }
}
container.viewContext.automaticallyMergesChangesFromParent = true
}
}
In the model editor, set each entity’s class to CDTrip, CDBucketListItem and so on. The SwiftData side uses Persistence.makeContainer() from above with the same URL.
Then the discipline:
- Change both schemas together. The session warns that mismatched entity version hashes can trigger a migration that deletes data. Every attribute you add to the
.xcdatamodeldgets added to the@Model, in the same release, with the same name and type. - One writer per entity. Decide which stack owns writes for each entity. Two stacks writing the same rows at the same time is where subtle bugs live.
- Use history to notice the other side’s changes. Apple’s sample detects widget edits in the main app by fetching SwiftData history with
fetchHistory(_:)(iOS 18) after a stored token, instead of adding flags or shared defaults.
Coexistence is a bridge, not a destination. Plan the release where the last Core Data code goes away.
What SwiftData still lacks
Fatbobman’s Reinventing piece explains why he moved a production app back to Core Data after SwiftData’s behavior on iOS 18 proved unstable, and his 2026 follow-up keeps the position for developers who value Core Data’s mature migration and compatibility. Comparing the two APIs directly shows the gaps that still decide real projects:
- Batch updates and inserts.
ModelContext(iOS 17) offersdelete(model:where:includeSubclasses:)for bulk deletes, and nothing likeNSBatchUpdateRequestorNSBatchInsertRequest. Updating a field on 100,000 rows means loading them. - Context control. No parent and child contexts, no merge policies to choose, no store options such as loading a store asynchronously, which Fatbobman lists among the controls he missed.
- CloudKit beyond the private database. Paul Hudson notes SwiftData sync covers only the private database. Sharing and the public database need
NSPersistentCloudKitContainer. - Fetched results for UIKit. Before iOS 27, live results outside SwiftUI meant rebuilding what
NSFetchedResultsControllergives you.ResultsObserver(iOS 27) closes that gap, but only for apps that can require iOS 27. - Relationship shape. To-many relationships are arrays without Core Data’s ordered option, and Fatbobman measured a performance cost for array-style operations on many-to-many relationships that
Setavoids in Core Data. - Model inheritance before iOS 26. Core Data’s abstract and parent entities map to SwiftData inheritance only from iOS 26.
SwiftData has gained ground each year: #Index and #Unique in iOS 18, inheritance in iOS 26, and ResultsObserver, HistoryObserver and @Attribute(.codable) in iOS 27. Check the gap list against your deployment target, not against the newest SDK.
When to stay on Core Data
Fatbobman’s recommendation for apps that must not break is to stay on Core Data and bring SwiftData’s ideas to it: models declared in code, enums stored by raw value, complex values stored as Codable, and an actor-based data layer. That is a better outcome than a half-finished migration.
Stay, or delay, if any of these is true:
- You support iOS 16 or earlier for the main app.
- You sync shared or public CloudKit data.
- You rely on batch requests for imports, cleanups or large updates.
- You have complex mapping-model migrations in your history and more coming.
- Your UIKit screens depend on
NSFetchedResultsControllerand you cannot require iOS 27.
Move if your app is SwiftUI-first, targets iOS 17 or later, syncs only private data, and its data operations are ordinary fetches, inserts and edits.
Traps
- Class name not equal to entity name. SwiftData sees a new entity and an orphaned old one. Your data looks gone.
- Optionality mismatch. A non-optional SwiftData property over an optional Core Data attribute that holds
nilrows fails when those rows load. - Forgetting persistent history in coexistence. The store opens read-only for one side.
- Letting SwiftData pick the default URL. It opens a new, empty
default.storenext to your real data. Users see an empty app and assume the update deleted everything. - Testing on a fresh install. Install the current App Store build, create data, then install the migrated build over it. A clean install hides every mapping mistake.
Checklist
| Step | Check |
|---|---|
Generate @Model code from the model file |
Class names equal entity names, optionality matches |
| Map special types | External storage, transformers, integer widths preserved |
Wrap in a first VersionedSchema |
Matches the shipped Core Data model exactly |
Point ModelConfiguration(url:) at the existing store |
No new default.store appears |
Coexistence only: history on, CD class prefix, same URL |
Both stacks read and write |
| Upgrade test from the App Store build | Row counts and relationships match before and after |
| Plan removal of the Core Data stack | A release is named for it |
Sources and further reading
- Migrate to SwiftData Apple, WWDC23
- Adopting SwiftData for a Core Data app Apple Developer Documentation
- ModelContext Apple Developer Documentation
- Reinventing Core Data Development with SwiftData Principles Fatbobman
- Why I'm Still Thinking About Core Data in 2026 Fatbobman
- How to sync SwiftData with iCloud Paul Hudson, Hacking with Swift