Two query restrictions per key using Parse and Swift

Guys, I'm trying to get all PFUsers whose username is not included in the array ( dontShowUsers. I also want to limit the query to a variable namethat gets all users whose username is equal to the name the user searches. However, when I do this:

findUsers.whereKey("username",containsString:name)
findUsers.whereKey("username",notContainedIn:dontShowUsers)

Each user shows. He forms both of these requests and combines them. I want to hold back the first whereKeywith the second whereKey. What would be the best way to do this?

+4
source share
2 answers

this is one way

println(geoPoint)
user["location"] = geoPoint
let rejectedUsers: [String] = user["rejected"].copy() as [String]
let acceptedUsers: [String] = user["accepted"].copy() as [String]
let ignoredUsers = rejectedUsers + acceptedUsers

var query = PFUser.query()
query.whereKey("location", nearGeoPoint: geoPoint)
query.whereKey("username", notEqualTo: user.username)
query.whereKey("gender", equalTo: user["interestedIn"])
query.whereKey("username", notContainedIn: ignoredUsers)
query.limit = 10
query.findObjectsInBackgroundWithBlock({
    (objects: [AnyObject]!, error2: NSError!) -> Void in
    if error2 != nil {
        println(error2)
    } else {
        if objects.isEmpty {
            println("empty query")
        } else {
            for object in objects {
                self.usernames.append(object.username)
                self.userImages.append(object["image"] as NSData)

, [ "reject" ] parse + "ignoredUsers"

:

query.whereKey( "username", notContainedIn: ignoredUsers)

+1

, , 2 , , , , , .

0

All Articles