1

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.

Aspid
  • 629
  • 6
  • 20

1 Answers1

0

thanx to @Asperi, I get that:

        fetchRequest.predicate = NSPredicate(format: "NOT (self in %@)", [setting.wrappedValue])
Aspid
  • 629
  • 6
  • 20