SwiftUI by Tutorials by By Audrey Tam & Audrey Tam & By Antonio Bello & By Bill Morefield

SwiftUI by Tutorials by By Audrey Tam & Audrey Tam & By Antonio Bello & By Bill Morefield

Author:By Audrey Tam & Audrey Tam & By Antonio Bello & By Bill Morefield
Language: eng
Format: epub
Publisher: Ray Wenderlich


Using binding for two-way reactions

A state variable is not only useful to trigger a UI update when its value changes; it also works the other way around.

How binding is (not) handled in UIKit

Think for a moment about a text field or text view in UIKit/AppKit: They both expose a text property, which you can use to set the value the text field/view displays and to read the text the user enters.

You can say that the UI component owns the data that it displays, or that the user enters, in its text property.

To get a notification when that value changes, you have to use either a delegate (text view) or subscribe to be notified when an editing changed event occurs (text field).

If you want to implement validation as the user enters text, you have to provide a method that is called every time the text changes. Then you have to manually update the UI. For example, you might enable or disable a button, or you could show a validation error.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.