@State + didSet Property Observer

)Hi,


I noticed that when you declare a view property as @State and add a didSet block to it, it will have no effect:


    @State var someStateValue : Int = 0 {
        didSet {
            print(someStateValue) // <-- never called
        }
    }


Makes sense because the property itself will be the State property wrapper and not the value.

But still, it would be nice to have a way to add code to such a property being changed.

Is there any way to react on a change of a @State property without making it @Published/using a ObservableObject?

(same question was asked here: https://stackoverflow.com/questions/56550713/how-can-i-run-an-action-when-a-state-changes )


Greetings,


Ralf

Use .onChange(of:)
@State + didSet Property Observer
 
 
Q