I was reading Paul Hudson’s article Dynamically filtering @FetchRequest with SwiftUI and thought I would share an improvement for declaring the singers @FetchRequest property that supports a dynamic predicate for filtering:

FilteredList.swift

import SwiftUI

struct FilteredList: View {
    @FetchRequest<Singer> var singers: FetchedResults<Singer>

    var body: some View {
        List(singers, id: \.self) { singer in
            Text("\(singer.wrappedFirstName) \(singer.wrappedLastName)")
        }
    }
}

ContentView.swift

...
    var body: some View {
        VStack{
            // list of matching singers
            FilteredList(singers: FetchRequest(sortDescriptors: [], predicate: NSPredicate(format: "lastName BEGINSWITH %@", lastNameFilter)))
...