Book Image

SwiftUI Cookbook - Second Edition

By : Giordano Scalzo, Edgar Nzokwe
Book Image

SwiftUI Cookbook - Second Edition

By: Giordano Scalzo, Edgar Nzokwe

Overview of this book

SwiftUI provides an innovative and simple way to build beautiful user interfaces (UIs) for all Apple platforms, from iOS and macOS through to watchOS and tvOS, using the Swift programming language. In this recipe-based cookbook, you’ll cover the foundations of SwiftUI as well as the new SwiftUI 3 features introduced in iOS 15 and explore a range of essential techniques and concepts that will help you through the development process. The cookbook begins by explaining how to use basic SwiftUI components. Once you’ve learned the core concepts of UI development, such as Views, Controls, Lists, and ScrollViews, using practical implementations in Swift, you'll advance to adding useful features to SwiftUI using drawings, built-in shapes, animations, and transitions. You’ll understand how to integrate SwiftUI with exciting new components in the Apple development ecosystem, such as Combine for managing events and Core Data for managing app data. Finally, you’ll write iOS, macOS, and watchOS apps by sharing the same SwiftUI codebase. By the end of this SwiftUI book, you'll have discovered a range of simple, direct solutions to common problems encountered when building SwiftUI apps.
Table of Contents (17 chapters)

Chapter 3: Exploring Advanced Components

In the previous chapters, we learned about the essential components of SwiftUI and how they can be put together to design great-looking apps. In this chapter, we'll discuss how to display large datasets efficiently by making use of SwiftUI's lazy stacks and lazy grids.

Lazy loaded views only load a subset of their content, the subset of items currently being displayed, and the content immediately preceding or succeeding the displayed subset.

We'll also learn how to present hierarchical data in an expandable list with sections. Finally, we'll introduce one of my favorite iOS features that's only available in SwiftUI Widgets. By the end of this chapter, you will be able to build apps that present large datasets and use collapsible lists and widgets.

In this chapter, we will cover the following recipes:

  • Using LazyHStack and LazyVStack
  • Displaying tabular content with LazyHGrid and LazyVGrid
  • Scrolling...