NSPredicate to return 除给定对象外的所有对象

NSPredicate to return all except given object

找不到允许我获取所有对象的 NSPredicate 语法,给定对象除外

  fetchRequest.predicate = NSPredicate(format: "SELF != %@", setting.objectID)

我的实体没有任何存储的 ID。在评论的某处发现语法但它不起作用:

Generic parameter 'Subject' could not be inferred

关于如何在不过滤多个属性的情况下过滤给定对象以外的所有对象的想法?

这是我的观点(使用 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{
        ...
    }
}

SettingsNSManagedObject,具有属性名称和高度。

感谢@Asperi,我明白了:

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