I have the following:
struct Event: Identifiable {
let id: Int
let name: String
let image: String
}
let events = [
Event(id: 0, name: "Host Tournament", image: "cup"),
Event(id: 1, name: "Post Club Info", image: "shield"),
Event(id: 3, name: "Share A Post", image: "write")
]
I want to be able for each Event to hold a separate view.
For example Event(id: 0, name: "Host Tournament", image: "cup", destinationView: PostView())
let events = [
Event(id: 0, name: "Host Tournament", image: "cup",destinationView: PostView()),
Event(id: 1, name: "Post Club Info", image: "shield",destinationView: ClubView()),
Event(id: 3, name: "Share A Post", image: "write", destinationView: StoryView())
]
So i can pass destinationView into my NavigationLink when i loop through events. Im not sure what type the PostView() should be defined as in my struct?
This is what Im currently doing:
ForEach(events) { event in
NavigationLink(destination: //PASS VIEW HERE FROM EVENT) {
VStack {
Image(event.image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 100, height: 100)
.padding(55)
Text(event.name)
.font(.system(.headline))
.padding(.bottom,20)
}
.padding()
.border(Color.black, width: 4)
.cornerRadius(10)
}.buttonStyle(PlainButtonStyle())
}
I want to be able to pass in a view depending on the Event its looping through.