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>
30 lines
742 B
Swift
30 lines
742 B
Swift
//
|
|
// DynamicFetchRequest.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 9/6/22.
|
|
//
|
|
// Used for FetchRequests with a dynamic predicate
|
|
// iOS 14 compatible view
|
|
//
|
|
|
|
import CoreData
|
|
import SwiftUI
|
|
|
|
struct DynamicFetchRequest<T: NSManagedObject, Content: View>: View {
|
|
@FetchRequest var fetchRequest: FetchedResults<T>
|
|
|
|
let content: (FetchedResults<T>) -> Content
|
|
|
|
var body: some View {
|
|
content(fetchRequest)
|
|
}
|
|
|
|
init(predicate: NSPredicate?,
|
|
sortDescriptors: [NSSortDescriptor] = [],
|
|
@ViewBuilder content: @escaping (FetchedResults<T>) -> Content)
|
|
{
|
|
_fetchRequest = FetchRequest<T>(sortDescriptors: sortDescriptors, predicate: predicate)
|
|
self.content = content
|
|
}
|
|
}
|