A modern framework for data modeling and management using Swift macros and native Swift types. SwiftData provides a declarative approach to persistence with automatic CloudKit sync support.
of iOS users worldwide can use SwiftData (iOS 17+ required)
| iOS Version | Market Share | Status |
|---|---|---|
| iOS 18.7 | 30.3% | Supported |
| iOS 18.6 | 29.8% | Supported |
| iOS 26.1 | 10.7% | Supported |
| iOS 18.5 | 6.0% | Supported |
| iOS 26.2 | 2.0% | Supported |
| iOS 18.3 | 1.8% | Supported |
| iOS 17.6 | 1.7% | Supported |
| iOS 26.0 | 1.3% | Supported |
| iOS 18.1 | 1.0% | Supported |
| iOS 17.5 | 1.0% | Supported |
Declarative schema using @Model macro
Automatic CloudKit sync with iCloud
Query data with Swift native types and predicates
Built-in migration support for schema changes
Relationship management between models
Integration with SwiftUI for reactive updates
Use the @Model macro to create a persistent data model
import SwiftData
@Model
class Trip {
var name: String
var destination: String
var startDate: Date
var endDate: Date
init(name: String, destination: String, startDate: Date, endDate: Date) {
self.name = name
self.destination = destination
self.startDate = startDate
self.endDate = endDate
}
}Fetch and filter data using @Query in SwiftUI
import SwiftUI
import SwiftData
struct TripListView: View {
@Query(sort: \Trip.startDate) var trips: [Trip]
var body: some View {
List(trips) { trip in
VStack(alignment: .leading) {
Text(trip.name)
.font(.headline)
Text(trip.destination)
.font(.subheadline)
}
}
}
}Add new data to the model container
import SwiftData
@Environment(\.modelContext) private var modelContext
func addTrip() {
let newTrip = Trip(
name: "Summer Vacation",
destination: "Paris",
startDate: Date(),
endDate: Date().addingTimeInterval(7 * 24 * 60 * 60)
)
modelContext.insert(newTrip)
}A modern framework for data modeling and management using Swift macros and native Swift types. SwiftData provides a declarative approach to persistence with automatic CloudKit sync support.
SwiftData is available on iOS 17 and later. Currently, 89.5% of iOS users worldwide can use this framework.
Related frameworks include Coredata, Cloudkit. Each has different capabilities and iOS version requirements.