Skoua
Skoua

Reputation: 3603

Starting with an empty SwiftUI @FetchRequest

I'm using @FetchRequest to get a big list (+7k) of entities and I'd like to initiate the view with an empty result set which will be filled later with searchable()

I tried using a predicate I know will return an empty set but it seems hacky, isn't there a more standard way to do that?

@FetchRequest(sortDescriptors: [
    SortDescriptor(\.infinitive)
], predicate: NSPredicate(format: "infinitive CONTAINS %@", "feofpezk")) var verbs: FetchedResults<Verb>

I saw that I can also try something like this:

NSPredicate(format: "FALSEPREDICATE")

Which seems just a bit less hacky but still.

Upvotes: 0

Views: 406

Answers (1)

Joakim Danielson
Joakim Danielson

Reputation: 51831

You can use NSPredicate(value:) with false to say "no values"

@FetchRequest(sortDescriptors: [
    SortDescriptor(\.infinitive)
], predicate: NSPredicate(value: false)) var verbs: FetchedResults<Verb>

Upvotes: 3

Related Questions