FetchRequest: Add descriptors
Adding the ability to send sort descriptors adds more flexibility for the DynamicFetchRequest backport. Use this to fix bookmarks sorting. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
6456b34210
commit
e31f9a07fe
2 changed files with 6 additions and 2 deletions
|
|
@ -21,9 +21,10 @@ struct DynamicFetchRequest<T: NSManagedObject, Content: View>: View {
|
|||
}
|
||||
|
||||
init(predicate: NSPredicate?,
|
||||
sortDescriptors: [NSSortDescriptor] = [],
|
||||
@ViewBuilder content: @escaping (FetchedResults<T>) -> Content)
|
||||
{
|
||||
_fetchRequest = FetchRequest<T>(sortDescriptors: [], predicate: predicate)
|
||||
_fetchRequest = FetchRequest<T>(sortDescriptors: sortDescriptors, predicate: predicate)
|
||||
self.content = content
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,10 @@ struct BookmarksView: View {
|
|||
@State private var bookmarkPredicate: NSPredicate?
|
||||
|
||||
var body: some View {
|
||||
DynamicFetchRequest(predicate: bookmarkPredicate) { (bookmarks: FetchedResults<Bookmark>) in
|
||||
DynamicFetchRequest(
|
||||
predicate: bookmarkPredicate,
|
||||
sortDescriptors: [NSSortDescriptor(keyPath: \Bookmark.orderNum, ascending: true)]
|
||||
) { (bookmarks: FetchedResults<Bookmark>) in
|
||||
List {
|
||||
if !bookmarks.isEmpty {
|
||||
ForEach(bookmarks, id: \.self) { bookmark in
|
||||
|
|
|
|||
Loading…
Reference in a new issue