I have a ForEach like this in SwiftUI:
ForEach(entries) { (e: MyType) in
NavigationLinkItem(entry: e)
}
now I need to also pass the previous Entry to my View (NavigationLinkItem) to do something like this:
ForEach(entries) { (e: MyType) in
NavigationLinkItem(entry: e, sucessor: ...)
}
How to realise that?
To keep ForEach
dynamic, find below possible approach (assuming MyType
is Identifiable
, and successor is optional)
ForEach(Array(entries.enumerated()), id: \.1.id) { (index, e) in
NavigationLinkItem(entry: e, sucessor: (index == 0 ? nil : self.entries[index - 1]))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With