whats new about grid views in swiftui?
Asked on 08/05/2024
1 search
In the latest updates to SwiftUI, there are several enhancements related to grid views:
-
Lazy Grids: You can now create lazy grids, such as
LazyVGrid
, which allows for efficient scrolling and dynamic content layout. For example, you can set up a grid with multiple columns and flexible sizing, and SwiftUI will handle the layout calculations for you. This is particularly useful for creating complex, scrollable layouts with minimal code.- Example: Setting up a lazy vertical grid with four columns and 40-point spacing, and using the aspect ratio modifier to manage item sizes.
-
Searchable Modifier: You can make grid content searchable by adding a state property to the view and using the
searchable
modifier. This allows users to filter the content dynamically as they type in the search term.- Example: Adding a
searchable
modifier to a grid view to filter content based on user input.
- Example: Adding a
-
Custom Containers: SwiftUI now supports more flexible composition in custom containers, allowing for more creative and dynamic layouts. This includes the ability to create sections within grids, similar to how lists can be sectioned.
- Example: Using a
Section
view within a custom container to organize grid content into sections.
- Example: Using a
-
Scrolling Enhancements: There are new APIs for fine-grained control over scroll views, including the ability to detect when a view's visibility changes due to scrolling. This can be used to create experiences like auto-playing videos when they come into view.
- Example: Using
onScrollGeometryChange
to react to changes in content offsets and sizes.
- Example: Using
For more detailed information, you can refer to the following sessions from WWDC 2024:
- What’s new in SwiftUI (16:18)
- Migrate your TVML app to SwiftUI (11:54)
- Demystify SwiftUI containers (10:42)
These sessions cover the new capabilities and enhancements in SwiftUI, including grid views and other layout improvements.

Platforms State of the Union
Discover the newest advancements on Apple platforms.

What’s new in SwiftUI
Learn how you can use SwiftUI to build great apps for any Apple platform. Explore a fresh new look and feel for tabs and documents on iPadOS. Improve your window management with new windowing APIs, and gain more control over immersive spaces and volumes in your visionOS apps. We’ll also take you through other exciting refinements that help you make expressive charts, customize and layout text, and so much more.

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.