Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created July 1, 2020 03:28
Show Gist options
  • Save azamsharp/b3f3f10bd8c74f424634249307e29ad2 to your computer and use it in GitHub Desktop.
Save azamsharp/b3f3f10bd8c74f424634249307e29ad2 to your computer and use it in GitHub Desktop.
//
// ContentView.swift
// Shared
//
// Created by Mohammad Azam on 6/30/20.
//
import SwiftUI
struct ListItem: Identifiable {
let id: UUID = UUID()
let name: String
var items: [ListItem]?
}
extension ListItem {
static func all() -> [ListItem] {
let animals = [ListItem(name: "🐢"),ListItem(name: "🐰")]
let fruits = [ListItem(name: "πŸ‘"), ListItem(name: "πŸ‰"), ListItem(name: "🍌")]
let cars = [ListItem(name: "πŸš—"), ListItem(name: "πŸš•"), ListItem(name: "πŸš™"), ListItem(name: "🚌"), ListItem(name: "🏎")]
return [ListItem(name: "Animals", items: animals), ListItem(name: "Fruits", items: fruits), ListItem(name: "Vehicles", items: cars)]
}
}
struct ContentView: View {
var body: some View {
List {
ForEach(ListItem.all()) { category in
Section(header: EmptyView()) {
OutlineGroup(category, children:
\.items) { item in
Text(item.name)
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment