-
Book Overview & Buying
-
Table Of Contents
SwiftUI Cookbook - Second Edition
By :
SwiftUI 2.0 introduced the LazyHStack and LazyVStack views. They can be used similar to the regular HStack and VStack views (discussed in Chapter 1, Using the Basic SwiftUI Views and Controls) but offer an extra advantage of lazy loading its content. The list's content is loaded just before it becomes visible on the device's screen, allowing the user to seamlessly scroll through large datasets with no perceptible UI lag or long load times. Let's create an app to see how this works in practice.
Create a new SwiftUI app called LazyStacks.
We will create an app that applies both the LazyHStack and LazyVStack views. We will ensure that each list row prints out some text to the console before being loaded. That way, we'll know what is being loaded and when. The steps are as follows:
ListRow view that has two properties: an id and a type. The ListRow view will print out some...