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
 

Videos

Abrir menú Cerrar menú
  • Colecciones
  • Todos los videos
  • Información

Más videos

  • Información
  • Código
  • Demystify SwiftUI containers

    Learn about the capabilities of SwiftUI container views and build a mental model for how subviews are managed by their containers. Leverage new APIs to build your own custom containers, create modifiers to customize container content, and give your containers that extra polish that helps your apps stand out.

    Capítulos

    • 0:00 - Introduction
    • 3:17 - Composition
    • 10:42 - Sections
    • 13:18 - Customization
    • 16:52 - Next steps

    Recursos

    • Creating custom container views
    • Forum: UI Frameworks
      • Video HD
      • Video SD

    Videos relacionados

    WWDC23

    • Demystify SwiftUI performance

    WWDC21

    • Demystify SwiftUI
  • Buscar este video…
    • 0:20 - SwiftUI Lists

      List {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      }
    • 0:36 - SwiftUI Lists

      List {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      
        ForEach(otherSongs) { song in
          Text(song.title)
        }
      }
    • 0:54 - SwiftUI Lists

      List {
        Section("Favorite Songs") {
          Text("Scrolling in the Deep")
          Text("Born to Build & Run")
          Text("Some Body Like View")
        }
      
        Section("Other Songs") {
          ForEach(otherSongs) { song in
            Text(song.title)
          }
        }
      }
    • 1:00 - SwiftUI Lists

      List {
        Section("Favorite Songs") {
          Text("Scrolling in the Deep")
          Text("Born to Build & Run")
          Text("Some Body Like View")
        }
      
        Section("Other Songs") {
          ForEach(otherSongs) { song in
            Text(song.title)
              .listRowSeparator(.hidden)
          }
        }
      }
    • 2:35 - Data-driven DisplayBoard

      @State private var songs: [Song] = [
        Song("Scrolling in the Deep"),
        Song("Born to Build & Run"),
        Song("Some Body Like View"),
      ]
      
      var body: some View {
        DisplayBoard(songs) { song in
          Text(song.title)
        }
      }
    • 2:47 - DisplayBoard implementation

      // Insert code snvar data: Data
      @ViewBuilder var content: (Data.Element) -> Content
      
      var body: some View {
        DisplayBoardCardLayout {
          ForEach(data) { item in
            CardView {
              content(item)
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 3:08 - Data-driven DisplayBoard

      @State private var songs: [Song] = [
        Song("Scrolling in the Deep"),
        Song("Born to Build & Run"),
        Song("Some Body Like View"),
      ]
      
      var body: some View {
        DisplayBoard(songs) { song in
          Text(song.title)
        }
      }
    • 3:30 - List composition

      List(songsFromSam) { song in
        Text(song.title)
      }
    • 3:46 - List composition

      List {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      }
    • 3:56 - List composition

      List {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      }
      
      List(songsFromSam) { song in
        Text(song.title)
      }
    • 4:05 - List composition

      List {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      }
      
      List {
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      }
    • 4:24 - List composition

      List {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      }
    • 4:59 - DisplayBoard implementation

      var data: Data
      @ViewBuilder var content: (Data.Element) -> Content
      
      var body: some View {
        DisplayBoardCardLayout {
          ForEach(data) { item in
            CardView {
              content(item)
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 5:15 - DisplayBoard implementation

      // DisplayBoard implementation
      
      @ViewBuilder var content: Content
      
      var body: some View {
        DisplayBoardCardLayout {
          ForEach(data) { item in
            CardView {
              content(item)
            }
          }
        }
        .background { BoardBackgroundView() }
      }
      
      DisplayBoard {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      }
      
      DisplayBoard {
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      }
    • 5:27 - DisplayBoard implementation

      @ViewBuilder var content: Content
      
      var body: some View {
        DisplayBoardCardLayout {
          ForEach(subviewOf: content) { subview in
            CardView {
              subview
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 5:52 - List composition

      List {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      }
    • 5:57 - DisplayBoard composition

      DisplayBoard {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      }
    • 6:12 - DisplayBoard implementation

      @ViewBuilder var content: Content
      
      var body: some View {
        DisplayBoardCardLayout {
          ForEach(subviewOf: content) { subview in
            CardView {
              subview
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 6:23 - DisplayBoard subviews

      DisplayBoard {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      }
    • 6:36 - Declared vs. resolved views

      DisplayBoard {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      }
      
      // 3 resolved subviews
      Text("Scrolling in the Deep")
      Text("Born to Build & Run")
      Text("Some Body Like View")
      
      // 9 resolved subviews
      Text("I Container Multitudes")
      …
      Text("Love Stack")
    • 7:11 - List subviews

      List {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      }
    • 7:19 - Declared vs. resolved views

      DisplayBoard {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      }
      
      // 3 resolved subviews
      Text("Scrolling in the Deep")
      Text("Born to Build & Run")
      Text("Some Body Like View")
      
      // 9 resolved subviews
      Text("I Container Multitudes")
      …
      Text("Love Stack")
    • 8:00 - Resolved ForEach

      // 1 declared view
      ForEach(songsFromSam) { song in
        Text(song.title)
      }
      
      // 9 resolved subviews
      Text("I Container Multitudes")
      …
      Text("Love Stack")
    • 8:16 - Resolved Group

      // 1 declared view
      Group {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      }
      
      // 3 resolved subviews
      Text("Scrolling in the Deep")
      
      Text("Born to Build & Run")
      
      Text("Some Body Like View")
    • 8:32 - Resolved EmptyView

      // 1 declared view
      EmptyView()	
      
      // Zero resolved subviews
    • 8:39 - Resolved if expression

      // 1 declared view
      if showFavoriteSongs {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      }
      
      // true → 3 resolved subviews
      Text("Scrolling in the Deep")
      Text("Born to Build & Run")
      Text("Some Body Like View")
      
      // false → Zero resolved subviews
    • 8:48 - DisplayBoard implementation

      @ViewBuilder var content: Content
      
      var body: some View {
        DisplayBoardCardLayout {
          ForEach(subviewOf: content) { subview in
            CardView {
              subview
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 9:11 - DisplayBoard composition

      DisplayBoard {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      }
    • 9:17 - DisplayBoard composition

      DisplayBoard {
        Text("Scrolling in the Deep")
        Text("Born to Build & Run")
        Text("Some Body Like View")
      
        ForEach(songsFromSam) { song in
          Text(song.title)
        }
      
        ForEach(songsFromSommer) { song in
          Text(song.title)
        }
      }
    • 9:44 - DisplayBoard implementation

      @ViewBuilder var content: Content
      
      var body: some View {
        DisplayBoardCardLayout {
          ForEach(subviewOf: content) { subview in
            CardView {
              subview
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 9:55 - DisplayBoard implementation

      @ViewBuilder var content: Content
      
      var body: some View {
        DisplayBoardCardLayout {
          Group(subviewsOf: content) { subviews in
            ForEach(subviews) { subview in
              CardView {
                subview
              }
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 10:19 - DisplayBoard implementation

      @ViewBuilder var content: Content
      
      var body: some View {
        DisplayBoardCardLayout {
          Group(subviewsOf: content) { subviews in
            ForEach(subviews) { subview in
              CardView(
                scale: subviews.count > 15 ? .small : .normal
              ) {
                subview
              }
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 10:47 - List sections

      List {
        Section("Favorite Songs") {
          Text("Scrolling in the Deep")
          Text("Born to Build & Run")
          Text("Some Body Like View")
        }
      
        Section("Other Songs") {
          ForEach(otherSongs) { song in
            Text(song.title)
          }
        }
      }
    • 11:03 - DisplayBoard sections

      DisplayBoard {
        Section("Matt's Favorites") {
          Text("Scrolling in the Deep")
          Text("Born to Build & Run")
          Text("Some Body Like View")
        }
        Section("Sam's Favorites") {
          ForEach(songsFromSam) { song in
            Text(song.title)
          }
        }
        Section("Sommer's Favorites") {
          ForEach(songsFromSommer) { song in
            Text(song.title)
          }
        }
      }
    • 11:26 - Implementing DisplayBoard sections

      DisplayBoard sections
      @ViewBuilder var content: Content
      
      var body: some View {
        DisplayBoardCardLayout {
          Group(subviewsOf: content) { subviews in
            ForEach(subviews) { subview in
              CardView(
                scale: subviews.count > 15 ? .small : .normal
              ) {
                subview
              }
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 11:35 - Implementing DisplayBoard sections

      @ViewBuilder var content: Content
      
      var body: some View {
        DisplayBoardSectionContent {
          content
        }
        .background { BoardBackgroundView() }
      }
      
      struct DisplayBoardSectionContent<Content: View>: View {
        @ViewBuilder var content: Content
        ...
      }
    • 11:42 - Implementing DisplayBoard sections

      @ViewBuilder var content: Content
      
      var body: some View {
        HStack(spacing: 80) {
          ForEach(sectionOf: content) { section in
            DisplayBoardSectionContent {
              section.content
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 12:48 - Implementing DisplayBoard section headers

      @ViewBuilder var content: Content
      
      var body: some View {
        HStack(spacing: 80) {
          ForEach(sectionOf: content) { section in
            VStack(spacing: 20) {
              if !section.header.isEmpty {
                DisplayBoardSectionHeaderCard { section.header }
              } 
              DisplayBoardSectionContent {
                section.content
              }
              .background { BoardSectionBackgroundView() }
            }
          }
        }
        .background { BoardBackgroundView() }
      }
    • 13:30 - List customization

      List {
        Section("Favorite Songs") {
          Text("Scrolling in the Deep")
          Text("Born to Build & Run")
          Text("Some Body Like View")
        }
      
        Section("Other Songs") {
          ForEach(otherSongs) { song in
            Text(song.title)
              .listRowSeparator(.hidden)
          }
        }
      }
    • 14:46 - Custom container values

      extension ContainerValues {
        @Entry var isDisplayBoardCardRejected: Bool = false
      }
      
      extension View {
        func displayBoardCardRejected(_ isRejected: Bool) -> some View {
          containerValue(\.isDisplayBoardCardRejected, isRejected)
        }
      }
    • 15:42 - Implementing DisplayBoard customization

      struct DisplayBoardSectionContent<Content: View>: View {
        @ViewBuilder var content: Content
      
        var body: some View {
          DisplayBoardCardLayout {
            Group(subviewsOf: content) { subviews in
              ForEach(subviews) { subview in
                let values = subview.containerValues
                CardView(
                  scale: (subviews.count > 15) ? .small : .normal,
                  isRejected: values.isDisplayBoardCardRejected
                ) {
                  subview
                }
              }
            }
          }
        }
      }
    • 16:15 - DisplayBoard customization

      DisplayBoard {
        Section("Matt's Favorites") {
          Text("Scrolling in the Deep")
            .displayBoardCardRejected(true)
          Text("Born to Build & Run")
          Text("Some Body Like View")
        }
        Section("Sam's Favorites") {
          ForEach(songsFromSam) { song in
            Text(song.title)
              .displayBoardCardRejected(song.samHasDibs)
          }
        }
        Section("Sommer's Favorites") {
          ForEach(songsFromSommer) { Text($0.title) }}}
        }
        .displayBoardCardRejected(true)
      }

Developer Footer

  • Videos
  • WWDC24
  • Demystify SwiftUI containers
  • 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