Open DaisukeNagata opened 4 years ago
import SwiftUI
struct ContentView: View {
let data =
FileItem(name: "users", children: [FileItem(name: "user1234", children: [FileItem(name:"Photos")])])
var body: some View {
OutlineGroup(data, children: \.children) { item in
Text ("\(item.description)")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct FileItem: Hashable, Identifiable, CustomStringConvertible {
var id: Self { self }
var name: String
var children: [FileItem]? = nil
var description: String {
switch (children) {
case nil:
return "📄 \(name)"
case .some(let children):
return children.count > 0 ? "📂 \(name)" : "📁 \(name)"
}
}
}
https://developer.apple.com/documentation/swiftui/outlinegroup