简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM