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
  • Discover Observation in SwiftUI

    Simplify your SwiftUI data models with Observation. We'll share how the Observable macro can help you simplify models and improve your app's performance. Get to know Observation, learn the fundamentals of the macro, and find out how to migrate from ObservableObject to Observable.

    Chapitres

    • 1:03 - What is Observation?
    • 4:23 - SwiftUI property wrappers
    • 7:34 - Advanced uses
    • 10:27 - ObservableObject

    Ressources

      • Vidéo HD
      • Vidéo SD

    Vidéos connexes

    WWDC23

    • Build an app with SwiftData
    • Demystify SwiftUI performance
    • Dive deeper into SwiftData
    • Expand on Swift macros
    • Meet SwiftData
    • Migrate to SwiftData
    • Model your schema with SwiftData
    • What’s new in SwiftUI
    • Write Swift macros
  • Rechercher dans cette vidéo…
    • 1:26 - Using @Observable

      @Observable class FoodTruckModel {    
          var orders: [Order] = []
          var donuts = Donut.all
      }
    • 2:12 - SwiftUI property tracking

      @Observable class FoodTruckModel {    
        var orders: [Order] = []
        var donuts = Donut.all
      }
      
      struct DonutMenu: View {
        let model: FoodTruckModel
          
        var body: some View {
          List {
            Section("Donuts") {
              ForEach(model.donuts) { donut in
                Text(donut.name)
              }
              Button("Add new donut") {
                model.addDonut()
              }
            }
          }
        }
      }
    • 3:12 - SwiftUI computed property tracking

      @Observable class FoodTruckModel {    
        var orders: [Order] = []
        var donuts = Donut.all
  var orderCount: Int { orders.count }
      }
      
      struct DonutMenu: View {
        let model: FoodTruckModel
          
        var body: some View {
          List {
            Section("Donuts") {
              ForEach(model.donuts) { donut in
                Text(donut.name)
              }
              Button("Add new donut") {
                model.addDonut()
              }
            }
            Section("Orders") {
              LabeledContent("Count", value: "\(model.orderCount)")
            }
          }
        }
      }
    • 4:41 - Using @State

      struct DonutListView: View {
          var donutList: DonutList
          @State private var donutToAdd: Donut?
      
          var body: some View {
              List(donutList.donuts) { DonutView(donut: $0) }
              Button("Add Donut") { donutToAdd = Donut() }
                  .sheet(item: $donutToAdd) {
                      TextField("Name", text: $donutToAdd.name)
                      Button("Save") {
                          donutList.donuts.append(donutToAdd)
                          donutToAdd = nil
                      }
                      Button("Cancel") { donutToAdd = nil }
                  }
          }
      }
    • 5:14 - Using @Environment

      @Observable class Account {
        var userName: String?
      }
      
      struct FoodTruckMenuView : View {
        @Environment(Account.self) var account
      
        var body: some View {
          if let name = account.userName {
            HStack { Text(name); Button("Log out") { account.logOut() } }
          } else {
            Button("Login") { account.showLogin() }
          }
        }
      }
    • 6:27 - Using @Bindable

      @Observable class Donut {
        var name: String
      }
      
      struct DonutView: View {
        @Bindable var donut: Donut
      
        var body: some View {
          TextField("Name", text: $donut.name)
        }
      }
    • 7:53 - Storing @Observable types in Array

      @Observable class Donut {
        var name: String
      }
      
      struct DonutList: View {
        var donuts: [Donut]
        var body: some View {
          List(donuts) { donut in
            HStack {
              Text(donut.name)
              Spacer()
              Button("Randomize") {
                donut.name = randomName()
              }
            }
          }
        }
      }
    • 9:18 - Manual Observation

      @Observable class Donut {
        var name: String {
          get {
            access(keyPath: \.name)
            return someNonObservableLocation.name 
          }
          set {
            withMutation(keyPath: \.name) {
              someNonObservableLocation.name = newValue
            }
          }
        } 
      }

Developer Footer

  • Vidéos
  • WWDC23
  • Discover Observation in SwiftUI
  • 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