Using just indices
public struct ReversedZIndex<Content: View>: View {
private let content: Content
public init(@ViewBuilder content: () -> Content) {
self.content = content()
}
public var body: some View {
Group(
subviewsOf: content,
transform: { collection in
let count = collection.count
ForEach(collection.indices, id: \\.self) { index in
collection[index]
.zIndex(Double(count - index))
}
}
)
}
}
Or using IndexedCollection