Two Query Constraints On One Key with Parse and Swift

前端 未结 2 1417
走了就别回头了
走了就别回头了 2021-01-19 06:14

guys, I am trying to get all the PFUsers whose username is not included in an array (dontShowUsers. I also want to limit the query with the variable name<

相关标签:
2条回答
  • 2021-01-19 06:18

    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)
    

    notice how i had to copy my user["rejected"] array from parse then i used + to create "ignoredUsers"

    then i was able to use:

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

    0 讨论(0)
  • 2021-01-19 06:19

    I would say that you can solve this without using 2 constraints, just before you execute the query, check if name is in the the array, and if it's not, just execute the query.

    0 讨论(0)
提交回复
热议问题