Swift CoreData view won't refresh If I have a predicate filter

Hello,

Im using a coredata to populate a list. When I add a new object the list dissent update until close the app and open it again. But this only started happening after I started using a predicate in the fetch request, Taking the Predicate out makes it work again. I tried everything else. This is the only thing that is causing it. Has anyone else experienced this?

@FetchRequest(
sortDescriptors: [NSSortDescriptor(key: "sobrietyDate_month", ascending: true),NSSortDescriptor(key: "sobrietyDate_day", ascending: true),NSSortDescriptor(key: "first_name", ascending: true)],
predicate: NSPredicate(format: "isVisible == %@", "1")
) var allContacts: FetchedResults<User>

if I take the predicate out it starts updating again. I tried this with Apple standard out of the box CoreData project, by adding a new object to core data as a bool then

@FetchRequest(
        sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)],
        predicate: NSPredicate(format: "isVisible == %@", "1"),
        animation: .default)
    private var items: FetchedResults<Item>

Same thing happens, Won't update live until the app is closed. Any ideas Thanks

Replies

Actally never mind i think it was the way i was checking for the bool, Should have been

NSPredicate(format: "boolAttribute = %d", true)

Its working now.