Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created October 19, 2020 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jubishop/d99715f71f1d44175dc1c9a68986a30b to your computer and use it in GitHub Desktop.
Save jubishop/d99715f71f1d44175dc1c9a68986a30b to your computer and use it in GitHub Desktop.
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