struct NavStack: View {
@State private var memes = [MemeModel]()
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path){
VStack{
Text("Pass search result")
.onTapGesture {
path.append(DataForSearch(searchTerm: "funny cats", memes: memes))
}
LazyVStack(spacing: 0){
ForEach(memes, id: .memeid){ meme in
Text(meme.title)
}
}
}
.navigationDestination(for: DataForSearch.self){ selection in
SearchResults(searchTerm: selection.searchTerm, memes: selection.$memes)
}
.onAppear{
memes.append(MemeModel(memeid: 123, title: "meme1"))
memes.append(MemeModel(memeid: 256, title: "meme2"))
}
}
}
}
struct SearchResults: View {
var searchTerm: String
@Binding var memes: [MemeModel]
var body: some View {
VStack(spacing: 50){
Text(searchTerm)
LazyVStack(spacing: 0){
ForEach(memes, id: .memeid){ meme in
Text(meme.title)
}
}
}
.onAppear{
memes.append(MemeModel(memeid: 345, title: "meme3"))
memes.append(MemeModel(memeid: 678, title: "meme4"))
}
}
}
struct DataForSearch: Hashable {
var searchTerm: String
@State var memes: [MemeModel]
}
struct MemeModel: Codable {
var memeid: Int
var title: String
}
I get the error:
Type ‘DataForSearch’ does not conform to protocol ‘Hashable’ for
struct DataForSearch: Hashable
I get the fix suggestion Do you want to add protocol stubs?
but I have no idea what the code is that is added with that.
2