I have an array of X number of items and I need to filter out specific items by uid. I've written the following predicate, which I believe to be correct. The problem I'm facing is that the Swift compiler is only allowing me to use the initialiser which accepts argumentArray.
let uids = ["34885a9f0897f8e9", "11364aca04e29be0", "c25047b10ad2a0d2"]
NSPredicate(format: "NOT (uid IN %@)", argumentArray: uids)
Which always resolves to the following:
NOT uid IN "18bbfd4d3f099297"
I know I'm missing something obvious here. How can I construct an NSPredicate to filter an array of 25 items down to an array of 22 items which does not include the uids
listed above? I need to pass this predicate into some Objective-C code.
Don't use NSPredicate(format:argumentArray:)
. The second parameter is provided to pass an array of arguments to replace multiple placeholder tokens in the format string.
Just pass uids
as the replacement for %@
NSPredicate(format: "NOT (uid IN %@)", uids)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With