Last active
October 5, 2023 20:24
-
-
Save beechtom/ddbaf0b430f81e21a2fa36fec92f31f2 to your computer and use it in GitHub Desktop.
SectionedQuery-07
This file contains 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
import SwiftData | |
@Model | |
class Item { | |
@Attribute(.unique) var name: String | |
var kind: String | |
} | |
struct ContentView: View { | |
@SectionedQuery private var results: SectionedResults<String, Item> | |
var body: some View { | |
List(results) { section in | |
Section(section.id) { | |
ForEach(section) { item in | |
Text(item.name) | |
} | |
} | |
} | |
} | |
init(order: SortOrder) { | |
_results = SectionedQuery(\.kind, sort: \.name, order: order) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment