Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift NSPredicate NOT IN

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.

like image 228
Brandon Schlenker Avatar asked Oct 01 '15 01:10

Brandon Schlenker


1 Answers

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)
like image 135
vadian Avatar answered Nov 10 '22 01:11

vadian