-
-
Save phillip5094/9f4bf615d542a890157e57b7b7d72c7b 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
struct ContentView: View { | |
struct FileItem: Hashable, Identifiable, CustomStringConvertible { | |
let id = UUID() | |
var name: String | |
var children: [FileItem]? = nil | |
var description: String { | |
switch children { | |
case nil: | |
return "π \(name)" | |
case .some(let children): | |
return children.isEmpty ? "π \(name)" : "π \(name)" | |
} | |
} | |
} | |
let fileHierarchyData: [FileItem] = [ | |
FileItem(name: "users", children: | |
[FileItem(name: "user1234", children: | |
[FileItem(name: "Photos", children: | |
[FileItem(name: "photo001.jpg"), | |
FileItem(name: "photo002.jpg")]), | |
FileItem(name: "Movies", children: | |
[FileItem(name: "movie001.mp4")]), | |
FileItem(name: "Documents", children: []) | |
]), | |
FileItem(name: "newuser", children: | |
[FileItem(name: "Documents", children: []) | |
]) | |
]), | |
FileItem(name: "download", children: [ | |
FileItem(name: "document.pdf") | |
]) | |
] | |
var body: some View { | |
List { | |
ForEach(fileHierarchyData) { fileItem in | |
Section { | |
OutlineGroup(fileItem.children ?? [FileItem](), children: \.children) { item in | |
Text("\(item.description)") | |
} | |
} header: { | |
Text(fileItem.name) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment