所以我有一个带有memberEmails的数组,现在我想查询未存储在这个数组中的用户:
var memberEmails: [String] = // ... is not empty
self.registeredUsers = self.realm.objects(AppUser).filter("email != '\(self.user.email!)' && '\(memberEmails)' !CONTAINS email")
抛出的错误消息:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "email != 'iphone5s@mail.com' && '["iphone5s@mail.com"]' !CONTAINS email"'
答案 0 :(得分:3)
你不应该使用Swift的字符串插值来进行查询,而是使用NSPredicate的%@
格式化程序:
var memberEmails: [String] = // ... is not empty
self.registeredUsers = self.realm.objects(AppUser.self).filter("email != %@ && NOT (email IN %@)", self.user.email, memberEmails)