ios - How to use NOT IN with Realm Swift -


i have list of realm objects (let's user) , want retrieve of them "john", "marc", "al' med" , on.

i tried following:

var namesstr = "" user in unwantedusers {     namesstr += "'" + user.name + "', " } namesstr = string(namesstr.characters.droplast().droplast()) let predicate = nspredicate(format: "not name in {%@}", namesstr) let remainingusers = uirealm.objects(user).filter(predicate) 

i tried nspredicate(format: "name not in {%@}", namesstr) crash (exception raised).

and second thing, how suppose escape names in nspredicate. if 1 of names has ' character, won't work.


edit

thanks le sang, here's functional result:

var userarr: [string] = [] user in unwanteduser {     userarr.append(user.name) } let predicate = nspredicate(format: "not name in %@", userarr) let remainingusers = uirealm.objects(user).filter(predicate) 

according realm document, these ways should work

let predicate = nspredicate(format: "not (name in %@)", namesstr) let predicate = nspredicate(format: "!(name in %@)", namesstr) let predicate = nspredicate(format: "not name in %@", namesstr) 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -