Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created October 19, 2020 03:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
import SwiftUI
func EnumList<T: Identifiable, V: View>(_ ary: Array<T>,
block:@escaping (Int, T) -> V) ->
List<Never, ForEach<Array<(offset: Int, element: T)>, T.ID, HStack<V>>> {
return List(Array(ary.enumerated()), id: \.element.id) { idx, item in
block(idx, item)
}
}
func EnumForEach<T: Identifiable, V: View>(_ ary: Array<T>,
block:@escaping (Int, T) -> V) ->
ForEach<Array<(offset: Int, element: T)>, T.ID, V> {
return ForEach(Array(ary.enumerated()), id: \.element.id) { idx, item in
block(idx, item)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment