How to use @state in SwiftUI

The SwiftUI framework is a reactive framework. No need to use any reactive framework like RxSwift to achieve reactive programming.

The @State is a ‘propertyWrapperstruct. It wraps a value of property or object with a view at runtime. Did you confused? , Consider below example, fullName variable stated by @State, and then it’s wrapped with TextField view, When you will change the input value of TextField. it will get stored in the fullName property, and yes forgot to say when state value gets changed it will automatically get reflected in UI, wherever you used @State wrapped variable like fullName, Text label get reflected changed value in TextField.

No need to use TextField lifecycle delegate in SwiftUI like textDidChange(), Its very crucial feature of SwiftUI over UIKit, For more to know more features of SwiftUI.

Leave a Comment