Skip to content

Instantly share code, notes, and snippets.

@jamesrochabrun
Created July 23, 2020 00:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesrochabrun/1d310e2d74c9f1ec53a7b62ce6b807d9 to your computer and use it in GitHub Desktop.
Save jamesrochabrun/1d310e2d74c9f1ec53a7b62ce6b807d9 to your computer and use it in GitHub Desktop.
GenericList using Swift UI.
// 1
struct GenericList<Element, RowContent: View>: View where Element: Identifiable {
// 2
private let items: [Element]
private let rowContent: (Element) -> RowContent
// 3
public init(_ items: [Element], @ViewBuilder rowContent: @escaping (Element) -> RowContent) {
self.items = items
self.rowContent = rowContent
}
// 4
var body: some View {
List(items, rowContent: rowContent)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment