Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Toni77777/399067b97d2a7686951b9bd737b579d8 to your computer and use it in GitHub Desktop.
Save Toni77777/399067b97d2a7686951b9bd737b579d8 to your computer and use it in GitHub Desktop.
extension List {
func emptyListPlaceholder(_ items: [Any], _ placeholder: AnyView) -> some View {
modifier(EmptyDataModifier(items: items, placeholder: placeholder))
}
}
struct ContentView: View {
@State var countries: [Country] = [] // Data source
var body: some View {
List(countries) { country in
Text(country.name)
.font(.title)
}
.emptyListPlaceholder(
countries,
AnyView(ListPlaceholderView()) // Placeholder
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment