Properties2
TypeConcept
Note createdFeb 17, 2025

In SwiftUI, when developing a View element, we can define properties using the @FocusedState property wrapper. It can be applied to a boolean property, and will allow us to store there if a given element is focused or not.

To define the element whose focus is to be stored, we can used in input fields like a TextField a .focused($property) modifier, which will two-way-bind the property and the element. Modifying the value of the property (for example, using a button) will also reflect is the field is to be focused or not.