This was avoided by regenerating the id with onDisappear
.
If there is no change in @State
, does that mean that you use the cache?
I'm going to learn more about it!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView_20191114: View { | |
@State var id = UUID().uuidString | |
var body: some View { | |
VStack { | |
NavigationLink(destination: DetailView_20191114(hoge: Hoge(id: id))) { | |
Text("Tap Me!") | |
.font(.title) | |
} | |
}.onDisappear { | |
self.id = UUID().uuidString | |
} | |
} | |
} | |
struct DetailView_20191114: View { | |
var hoge: Hoge | |
var body: some View { | |
Text("id: \(hoge.id)") | |
} | |
} | |
struct Hoge { | |
var id: String | |
} | |
struct ContentView_20191114_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView_20191114() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView_20191114: View { | |
var body: some View { | |
VStack { | |
NavigationLink(destination: DetailView_20191114(hoge: Hoge())) { | |
Text("Tap Me!") | |
.font(.title) | |
} | |
} | |
} | |
} | |
struct DetailView_20191114: View { | |
var hoge: Hoge | |
var body: some View { | |
VStack { | |
Text("id: \(hoge.id)") | |
} | |
} | |
} | |
struct Hoge { | |
var id: String = UUID().uuidString | |
} | |
struct ContentView_20191114_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView_20191114() | |
} | |
} |