Created
July 1, 2020 03:28
-
-
Save azamsharp/b3f3f10bd8c74f424634249307e29ad2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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