Why I am not success to pass data from one view to another view in SwiftUI?

I have a problem when try to pass data from one view to another view, it is throw an error for

  ImageDetails()

as a "Missing argument for parameter 'data' in call" I do not know what I missed?

struct ImageModel: Identifiable, Hashable {
  var id = UUID().uuidString
  var name: String
 
}

var datas = [
   
  ImageModel(name: "davis"),

]
struct ImageRowView: View {
  var data: ImageModel
  var body: some View {
  
        NavigationLink(destination: ImageDetailsView(data: ImageModel)){
           
          HStack{}
}}}
struct ImageDetailsView: View {
  
  var body: some View {
     
    ImageDetails()
  }
}

struct ImageDetailsView_Previews: PreviewProvider {
  static var previews: some View {
     
    ImageDetailsView()
     
  }
}


struct ImageDetails : View {
  
  var data: ImageModel

  var body: some View{

  VStack{
            Text(data.name)
          
          }
}
Answered by Claude31 in 705441022

You have declared a var in ImageDetails and did not initialise it.

So you have to do it when you call (creating the instance), such as:

struct ImageDetailsView: View {
  
  var body: some View {
     
    ImageDetails(data:  ImageModel(name: "davis"))
  }
}
Accepted Answer

You have declared a var in ImageDetails and did not initialise it.

So you have to do it when you call (creating the instance), such as:

struct ImageDetailsView: View {
  
  var body: some View {
     
    ImageDetails(data:  ImageModel(name: "davis"))
  }
}
Why I am not success to pass data from one view to another view in SwiftUI?
 
 
Q