What’s the old and new way of creating collections vies?
Generated on 8/2/2024
1 search
The old way of creating collection views in SwiftUI involved using a list initializer with a collection parameter, which is essentially a convenience for creating a ForEach
view. This method generates views for each element in a collection and provides those to its container. This approach allows for creating more advanced constructions, such as multiple collections of data organized into sections.
The new way, as discussed in the session "Demystify SwiftUI containers," involves using a more flexible composition approach. Instead of being limited to a single collection of data, you can now initialize containers using a ViewBuilder
. This allows for combining different kinds of content together. For example, you can define some rows statically and others dynamically within the same list. The new API ForEachSubview
allows you to transform each subview into a different kind of view, providing more flexibility in how you compose your UI.
For more details, you can refer to the session Demystify SwiftUI containers (03:03).
Relevant Sessions
SwiftUI essentials
Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.
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.
What’s new in UIKit
Explore everything new in UIKit, including tab and document launch experiences, transitions, and text and input changes. We’ll also discuss better-than-ever interoperability between UIKit and SwiftUI animations and gestures, as well as general improvements throughout UIKit.
Migrate your TVML app to SwiftUI
SwiftUI helps you build great apps on all Apple platforms and is the preferred toolkit for bringing your content into the living room with tvOS 18. Learn how to use SwiftUI to create familiar layouts and controls from TVMLKit, and get tips and best practices.