Skip to content

Instantly share code, notes, and snippets.

@beechtom
Last active October 5, 2023 20:24
Show Gist options
  • Save beechtom/ddbaf0b430f81e21a2fa36fec92f31f2 to your computer and use it in GitHub Desktop.
Save beechtom/ddbaf0b430f81e21a2fa36fec92f31f2 to your computer and use it in GitHub Desktop.
SectionedQuery-07
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