New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new sortDescriptor to FetchRequest extensions #8
Comments
Hi @hfhbd 👋! PredicateKit's SwiftUI extension has support for sort descriptors. For example, it's possible to write something like the following. import PredicateKit
import SwiftUI
struct ContentView: View {
@SwiftUI.FetchRequest(
fetchRequest: FetchRequest(predicate: (\Note.text).contains("Hello, World!"))
.sorted(by: \Note.creationDate)
)
var notes: FetchedResults<Note>
// ...
}
Does this match what you're requesting? |
Hey @ftchirou, yes I do know this function and I use it :) With iOS 15, Apple provided another constructor with // For example, not tested
extension SwiftUI.FetchRequest {
init(sortDescriptors: [SortDescriptor<Result>], predicate: Predicate? = nil, animation: Animation? = nil) {
super.init(fetchRequest: FetchRequest(predicate: predicate).sorted(by: sortDescriptors)
}
} If you like it, I will provide a PR. |
Hey @hfhbd! My apologies for the delay.
Yes, please open a PR when you have some time. |
@ftchirou I developed the constructor, but the new SortDescriptor in Foundation is not compatible with your |
Hey, thanks for this nice library!
I am using iOS 15, which added a new property to the
SwiftUI.FetchRequest
, asortDescriptor
. It would be nice, if you could add this property in your extensions too, with@available(ios15)
Reference: https://developer.apple.com/documentation/swiftui/fetchrequest/init(sortdescriptors:predicate:animation:)-462jp?changes=latest_major
The text was updated successfully, but these errors were encountered: