I try to remove some Persons
from a FetchRequest
, but the object itself is not removed and only the name property is empty. I load it like this:
var filteredPersons: FetchRequest<Person>
init() {
let personFilterIds = ["1234", "2345", "3456"]
filteredPersons = FetchRequest<Person>(
entity: Person.entity(),
sortDescriptors: [NSSortDescriptor(keyPath: \Person.name, ascending: false)],
predicate: NSPredicate(format: "NOT (id IN %@)", personFilterIds)
)
}
I then display the remaining Persons
in this way:
var body: some View {
ForEach(filteredPersons.wrappedValue, id: \.self) { person in
// Why do I need this if to only display the filtered ones?
// Why does the person object still exist in the list? (person.id is for example still there)
if (!person.name.isEmpty) {
Text(person.name)
}
}
}
Why is it not working correctly without the if (!person.name.isEmpty)
? Am I doing the filtering wrong?