1

I have an array of objectIds = ["LlbAXkqOL4", "v7lSgUunbR"]

If I have only one object id, then I can use,

query.getObjectInBackgroundWithId("A2332xsdas2") Since I have many objectIds, I am following this code:

    let userQuery = PFUser.query()
    userQuery?.whereKey("username", equalTo: self.user!.username!)
    userQuery?.findObjectsInBackgroundWithBlock {
        (object, error) -> Void in
        if object != nil
        {
            for messageObject in object! {
                self.importedArray = ((messageObject as! PFObject)["AllEventsId"] as? [String]!)!
                println("importedArray = \(self.importedArray)")
            }
        }
    }


    var query:PFQuery = PFQuery(className: "Events")
    query.whereKey("objectId", containedIn: self.importedArray)
    query.whereKey("EventSTDTime", greaterThan: zDate)
    query.findObjectsInBackgroundWithBlock {
        (object, error) -> Void in
        if object != nil
        {
            println(objects)
        }
     }      

Here is the screenshot: screenshot

But this method is not working as it fetched all the id under the class Events

9
  • I didnt get what problem you are facing. What do you mean by "is not working as it fetched all the id under the class Events". Please give more details. Commented Sep 10, 2015 at 16:56
  • In Events class, if I have 10 rows, it is fetching all the 10 rows, I want only the rows that have the objectId am mentioning in the array: objectIds Commented Sep 10, 2015 at 16:58
  • Its working for me. does this importedArray has the right data? Commented Sep 10, 2015 at 17:37
  • yes, I could get the importedArray in console and it is good. Commented Sep 10, 2015 at 17:40
  • show me what you trying Commented Sep 10, 2015 at 17:46

1 Answer 1

7

Not sure why your request is returning the whole class info. But the point here is that parse background methods run assynchronously and you cant iterate over them.

The solution that might work for you is the following:

var query:PFQuery = PFQuery(className: "Events")
    query.whereKey("objectId", containedIn: objectIds)
    query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
                println(objects)
    })
Sign up to request clarification or add additional context in comments.

1 Comment

you sure those ids are stored in your database? could you please edit your question with a sreenshot of your parse table?

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.