import SwiftUI struct ContentView: View { var body: some View { NavigationView { NavigationLink(destination: SecondView(Counter.shared.count)) { Text("Open") } } } } struct SecondView: View { @State var count: Int var body: some View { VStack { Text("\(Counter.shared.count)") Text("\(count)") Stepper("", value: $count) .labelsHidden() } .onDisappear { Counter.shared.count = self.count } } } struct Counter { var count: Int = 0 static var shared = Counter() }
こうしないといけないかな (edited)