View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vidéos

Ouvrir le menu Fermer le menu
  • Collections
  • Toutes les vidéos
  • À propos

Plus de vidéos

  • À propos
  • Code
  • Meet SwiftData

    SwiftData is a powerful and expressive persistence framework built for Swift. We'll show you how you can model your data directly from Swift code, use SwiftData to work with your models, and integrate with SwiftUI.

    Chapitres

    • 0:00 - Intro
    • 1:07 - Using the model macro
    • 3:17 - Working with your data
    • 7:02 - Use SwiftData with SwiftUI
    • 8:10 - Wrap-up

    Ressources

    • SwiftData
    • Adopting SwiftData for a Core Data app
      • Vidéo HD
      • Vidéo SD

    Vidéos connexes

    WWDC23

    • Build an app with SwiftData
    • Discover Observation in SwiftUI
    • Dive deeper into SwiftData
    • Migrate to SwiftData
    • Model your schema with SwiftData
    • Swift 的新功能
    • What’s new in SwiftUI
  • Rechercher dans cette vidéo…
    • 1:27 - Adding @Model to Trip

      import SwiftData
      
      @Model
      class Trip {
          var name: String
          var destination: String
          var endDate: Date
          var startDate: Date
       
          var bucketList: [BucketListItem]? = []
          var livingAccommodation: LivingAccommodation?
      }
    • 2:46 - Providing options for @Attribute and @Relationship

      @Model
      class Trip {
          @Attribute(.unique) var name: String
          var destination: String
          var endDate: Date
          var startDate: Date
       
          @Relationship(.cascade) var bucketList: [BucketListItem]? = []
          var livingAccommodation: LivingAccommodation?
      }
    • 3:43 - Initialize a ModelContainer

      // Initialize with only a schema
      let container = try ModelContainer([Trip.self, LivingAccommodation.self])
      
      // Initialize with configurations
      let container = try ModelContainer(
          for: [Trip.self, LivingAccommodation.self],
          configurations: ModelConfiguration(url: URL("path"))
      )
    • 3:58 - Creating a model container in SwiftUI

      import SwiftUI
      
      @main
      struct TripsApp: App {
          var body: some Scene {
              WindowGroup {
                  ContentView()
              }
              .modelContainer(
                  for: [Trip.self, LivingAccommodation.self]
              )
          }
      }
    • 4:20 - Accessing the environment's ModelContext

      import SwiftUI
      
      struct ContextView : View {
          @Environment(\.modelContext) private var context
      }
    • 5:13 - Building a predicate

      let today = Date()
      let tripPredicate = #Predicate<Trip> { 
          $0.destination == "New York" &&
          $0.name.contains("birthday") &&
          $0.startDate > today
      }
    • 5:32 - Fetching with a FetchDescriptor

      let descriptor = FetchDescriptor<Trip>(predicate: tripPredicate)
      
      let trips = try context.fetch(descriptor)
    • 5:46 - Fetching with fetch and sort descriptors

      let descriptor = FetchDescriptor<Trip>(
          sortBy: SortDescriptor(\Trip.name),
          predicate: tripPredicate
      )
      
      let trips = try context.fetch(descriptor)
    • 6:15 - Working with a ModelContext

      var myTrip = Trip(name: "Birthday Trip", destination: "New York")
      
      // Insert a new trip
      context.insert(myTrip)
      
      // Delete an existing trip
      context.delete(myTrip)
      
      // Manually save changes to the context
      try context.save()
    • 7:38 - Using @Query in SwiftUI

      import SwiftUI
      
      struct ContentView: View  {
          @Query(sort: \.startDate, order: .reverse) var trips: [Trip]
          @Environment(\.modelContext) var modelContext
          
          var body: some View {
             NavigationStack() {
                List {
                   ForEach(trips) { trip in 
                       // ...
                   }
                }
             }
          }
      }

Developer Footer

  • Vidéos
  • WWDC23
  • Meet SwiftData
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines