Using Realm DB in a swift application. I'm trying to filter the results with a predicate as follows:
class func fetchUsersFromDB(usersId: [String]) -> [User]{
var users = [User]()
let realm = Realm()
let predicate = NSPredicate(format: "objectId IN %@", argumentArray: usersId)
var allUsers = realm.objects(User).filter(predicate)
users = Array(allUsers)
return users
}
But this won't compile. I get this error:
Terminating app due to uncaught exception 'Invalid value', reason: 'IN clause requires an array of items'
Any ideas what I'm doing wrong?
Remove the argumentArray:
label, as with it you're calling the wrong initializer for NSPredicate:
let predicate = NSPredicate(format: "objectId IN %@", usersId)
As of Swift 3, just use Array(usersId)
instead of usersId
.
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