Created
October 5, 2023 19:56
-
-
Save beechtom/791083b9eb8a520812fc7d8942dc9a9f to your computer and use it in GitHub Desktop.
SectionedQuery-04
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 SwiftUI | |
import SwiftData | |
@propertyWrapper | |
struct SectionedQuery<SectionIdentifier, Result> | |
where SectionIdentifier: Hashable, Result: PersistentModel { | |
private let sectionIdentifier: KeyPath<Result, SectionIdentifier> | |
@Query private var results: [Result] | |
var wrappedValue: SectionedResults<SectionIdentifier, Result> { | |
SectionedResults(sectionIdentifier: sectionIdentifier, | |
results: results) | |
} | |
init<Value>(_ sectionIdentifier: KeyPath<Result, SectionIdentifier>, | |
filter: Predicate<Result>? = nil, | |
sort keyPath: KeyPath<Result, Value>, | |
order: SortOrder = .forward, | |
animation: Animation = .default) where Value: Comparable { | |
self.sectionIdentifier = sectionIdentifier | |
_results = Query(filter: filter, | |
sort: keyPath, | |
order: order, | |
animation: animation) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment