-
Migrate to SwiftData
Discover how you can start using SwiftData in your apps. We'll show you how to use Xcode to generate model classes from your existing Core Data object models, use SwiftData alongside your previous implementation, or even completely replace your existing solution.
Before watching this session, make sure you check out "Meet SwiftData."Capítulos
- 0:00 - Intro
- 1:06 - Generate model classes
- 3:05 - Complete adoption
- 6:43 - Coexists with Core Data
- 10:47 - Wrap-up
Recursos
Vídeos relacionados
WWDC23
-
Buscar neste vídeo...
-
-
4:37 - Creating a ModelContainer in SwiftUI
@main struct TripsApp: App { var body: some Scene { WindowGroup { ContentView() } .modelContainer( for: [Trip.self, BucketListItem.self, LivingAccommodation.self] ) } } -
4:57 - Object creation in Core Data
@Environment(\.managedObjectContext) private var viewContext let newTrip = Trip(context: viewContext) newTrip.name = name newTrip.destination = destination newTrip.startDate = startDate newTrip.endDate = endDate -
5:30 - Object creation in SwiftData
@Environment(\.modelContext) private var modelContext let trip = Trip( name: name, destination: destination, startDate: startDate, endDate: endDate ) modelContext.insert(object: trip) -
6:16 - Fetch with Query in SwiftData
@Query(sort: \.startDate, order: .forward) var trips: [Trip] -
7:30 - Setting store path and enabling persistent history tracking in Core Data
let url = URL(fileURLWithPath: "/path/to/Trips.store") if let description = container.persistentStoreDescriptions.first { description.url = url description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) } -
9:11 - Ensuring Core Data and SwiftData class names are unique
class CDTrip: NSManagedObject { // ... } @Model final class Trip { // ... }
-