When I try to replicate the example from SwiftUI documentation on onChange modifier and capture the previous value, inside the closure the previous value is equal to the new value, not the old one.
In the documentation example, the onChange modifier is attached to the body property, not to a view inside it. Is this how it should be used? Attaching it to the body property in Xcode 12.0 beta (12A6159) doesn't compile.
Code Block swift struct ContentView: View { @State private var isSubscribed = false var body: some View { Toggle("Subscribe", isOn: $isSubscribed) .onChange(of: isSubscribed) { [isSubscribed] newState in print(isSubscribed) print(newState) } } }
In the documentation example, the onChange modifier is attached to the body property, not to a view inside it. Is this how it should be used? Attaching it to the body property in Xcode 12.0 beta (12A6159) doesn't compile.