0

I have an array of names, and a column which is of type string, and I am trying to get the information. When I use a for loop for each value in the where key, I get A LOT of the same info, so say there are 5 names, and I am trying to pick up rate (an Integer) I will get like 100 values instead of just 5.

var name = ["Dog", "Cat", "Monkey"]
let query = PFQuery(className: "Animals")
    query.whereKey(not sure what to put since it is an array)
    query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error: NSError?) in
        if(error == nil){
            for object in objects!{


                        if let rating = object["rate"] as? Int{
                            self.rater.append(rating)
                            print("rating \(self.rater)") //There are like 75-100 values
                        }
            }
        }else{
            print(error)
            }
        }

2 Answers 2

1

I don't know much about Parse, but there is this method -whereKey:containedIn: which takes an array. Won't that work for you? (sorry I didn't find the Swift documentation)

Documentation says:

-whereKey:containedIn:

Add a constraint to the query that requires a particular key’s object to be contained in the provided array.

Declaration OBJECTIVE-C

- (nonnull instancetype)whereKey:(nonnull NSString *)key
                 containedIn:(nonnull NSArray *)array;

Parameters:

-key The key to be constrained.

-array The possible values for the key’s object.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this, it will surely works.

var names = ["Dog", "Cat", "Monkey"]
    let query = PFQuery(className: "Animals")
        query. whereKey("name", containedIn: names)
        query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error: NSError?) in
            if(error == nil){
                for object in objects!{


                            if let rating = object["rate"] as? Int{
                                self.rater.append(rating)
                                print("rating \(self.rater)") //There are like 75-100 values
                            }
                }
            }else{
                print(error)
                }
            }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.