hklel
hklel

Reputation: 1634

NSPredicate get entities with attribute not in a given array

I am using CloudKit to store and sync some data in my app. Let's say I have a record type with an attribute named key. I want to fetch all records with key not in a given array unwantedKeyArray.

I tried

let predicate = NSPredicate(format: "key NOT IN %@", unwantedKeyArray)

But the app crashed with error saying

'Unable to parse the format string "key NOT IN %@"'

So what's the correct way to create a NSPredicate to achieve my goal?

(Although I use Swift in my app and in this question description, answers in ObjC are also welcome)

Upvotes: 0

Views: 69

Answers (1)

Oleg Gordiichuk
Oleg Gordiichuk

Reputation: 15512

Try this code example :

   NSPredicate(format: "NOT (key IN %@)", unwantedKeyArray)

Upvotes: 1

Related Questions