↓を実行すると SecondView
を開く度に count
が 0
に戻るんですが、どういう挙動でしょう? import SwiftUI struct ContentView: View { var body: some View { NavigationView { NavigationLink(destination: SecondView()) { Text("Open") } } } } struct SecondView: View { @State var count: Int = Counter.shared.count 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() }