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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -