can't find syntax of NSPredicate which allows me to fetch all the objects, except one given
fetchRequest.predicate = NSPredicate(format: "SELF != %@", setting.objectID)
My entity does not have any stored ID. somewhere in comments found that syntaxes but it does not work:
Generic parameter 'Subject' could not be inferred
any ideas how to filter all objects but one given, without filtering several properties?
that's my view (using SwiftUI):
struct SettingsChoiseView: View {
@Binding var actualSetting: Settings
@Environment(\.managedObjectContext) var moc: NSManagedObjectContext
@FetchRequest var avalibleSettings: FetchedResults<Settings>
init(setting: Binding<Settings>) {
let fetchRequest: NSFetchRequest< Settings> = Settings.fetchRequest()
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \ Settings.name, ascending: true),
NSSortDescriptor(keyPath: \ Settings.height, ascending: true)]
fetchRequest.predicate = NSPredicate(format: "!(name = %@ && height == %d)", setting.name.wrappedValue, setting.height.wrappedValue)
self._avalibleSettings = FetchRequest(fetchRequest:fetchRequest)
}
var body: some View{
...
}
}
Settings
is NSManagedObject
with properties name and height.