我想向FetchRequest添加 predicate ...
如果我将其放入FetchRequest中,它将不起作用:
not working
@SectionedFetchRequest(sectionIdentifier: \Product.manufacturer?.name,
sortDescriptors: [NSSortDescriptor(keyPath: \Product.name, ascending: true)],
predicate: NSPredicate(format: "trashed = true")) // <-- not working
var products: SectionedFetchResults<String?, Product>
但当我使用.onChange
将其添加到FetchedResults时,它正在工作
working
@SectionedFetchRequest(sectionIdentifier: \Product.manufacturer?.name,
sortDescriptors: [NSSortDescriptor(keyPath: \Product.name, ascending: true)],
// -- no predicate in FetchRequest --)
var products: SectionedFetchResults<String?, Product>
var body: some View {
List {
ForEach(products) { product in
Text(product.name)
}
Button {
testPred.toggle()
} label: {
Text("activate predicate")
}
}
}
.onChange(of: isSortedAscending) { _ in
products.nsPredicate = NSPredicate(format: "trashed = true") // <-- working
}
edit 1
我现在唯一的想法是问这是否可能与这些设置有关?
publicDescription.cloudKitContainerOptions = options
publicDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
publicDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
1条答案
按热度按时间nhaq1z211#
我发现了问题,但我现在真的要发疯了!
同品种器械一直有效。
但是,我已经将以下代码附加到视图:
这一次又一次立即将 predicate 设置为
nil
。