The reason the image detail view always shows davis is because your image details view always uses the davis image model.
struct ImageDetailsView: View {
var body: some View {
ImageDetails(data: ImageModel(name: "davis"))
}
}
You need to add a property to the image details view that stores the image model to display.
@Binding var imageModel: ImageModel
Pass the property to ImageDetails.
ImageDetails(data: $imageModel)
I don't see any list code, but you have to create a @State property in the view that has the list to store the selected list item.
@State private var selectedImage: ImageModel? = nil
Your list code should contain a navigation link to the details view.
NavigationLink(destination: ImageDetailsView(imageModel: $selectedImage))
Now the details view would show the selected image. But your code has a problem. In both ImageRowView and ImageDetails, you have the following property:
var data: ImageModel
SwiftUI views do not live long. When a change occurs to a view, SwiftUI creates a brand new view. When SwiftUI creates a new view, you will lose the contents of the data variable. In ImageRowView, you should declare a @State property like the selectedImage property I declared earlier. When you use @State, SwiftUI will keep the property when it creates a new view. In ImageDetails you should declare a @Binding property, like the imageModel binding I declared earlier, so it will show the selected image model.
I can't guarantee that everything will work now, but it should get you towards a solution. If you need a working example, the GitHub project at the following URL provides an example of handling list selection and working with @State and @Binding:
https://github.com/SwiftDevJournal/WikiDemo