Created
June 30, 2020 20:57
-
-
Save azamsharp/561e26e430b20d67f6193fd148fd60c3 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 Category: Identifiable { | |
let id: UUID = UUID() | |
let name: String | |
let products: [Product] | |
} | |
extension Category { | |
static func all() -> [Category] { | |
let animals = [Product(name: "πΆ"),Product(name: "π°")] | |
let fruits = [Product(name: "π"), Product(name: "π"), Product(name: "π")] | |
return [Category(name: "Animals", products: animals), Category(name: "Fruits", products: fruits)] | |
} | |
} | |
struct Product: Identifiable { | |
let id: UUID = UUID() | |
let name: String | |
} | |
struct ContentView: View { | |
var body: some View { | |
List { | |
ForEach(Category.all()) { category in | |
Section(header: Text(category.name)) { | |
OutlineGroup(category, children: \.products) { product in | |
Text(product.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