Home > database >  Starting with an empty SwiftUI @FetchRequest
Starting with an empty SwiftUI @FetchRequest

Time:12-15

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.

CodePudding user response:

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

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