24. SwiftUI Lifecycle Event Modifiers

One of the key strengths of SwiftUI is that, through use of features such as views, state properties and observable objects, much of the work required in making sure an app handles lifecycle changes correctly is performed automatically.

It is still often necessary, however, to perform additional actions when certain lifecycle events occur. An app might, for example, need to perform a sequence of actions at the point that a view appears or disappears within a layout. Similarly, an app may need to execute some code each time a value changes, or to detect when a view becomes active or inactive. All of these requirements and more can be met by making use of a set of event modifiers provided by SwiftUI.

Since ...

Get SwiftUI Essentials – iOS 14 Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.