0

I am trying to query an array from Parse.com to an empty array.

My empty array:

var commentsArray = [NSArray]()

My query code:

var query1 = PFQuery(className: "currentUploads")
        query1.whereKey("objectId", equalTo: "ImxZwVx7L8")
        query1.findObjectsInBackgroundWithBlock{
            (objects: [AnyObject]?, error: NSError?) -> Void in
            if error == nil {
                if let objects = objects as? [PFObject] {
                    for object in objects {

                        //For each object in the class object, append it to myArray
                        if let dataArray = object["comments"] as? NSArray {
                            self.commentsArray.append(dataArray)

                            println("codeBelow")
                            println(self.commentsArray)
                            println(self.commentsArray.count)
                        }
                    }
                }
            } else {
                println("\(error?.userInfo)")
            }
        }

In the output I get this:

codeBelow
[(
    abc,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    def,
    tdrthdrthdrthdrthdrhtrthdrthdrthdrthdrthdrthdrthdrthdrth,
    "jdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrt dhrt hdrthdrthdrthdrh 5hsr5d r5hdr5h drthr t hdrt hkl"
)]
1

As you can see, the output count gives me 1, but it should give 38. If I do println(dataArray.count) it gives me output 38. How come? What is wrong?

1 Answer 1

1

First, create an empty array:

var commentsArray: [String] = [String]()

Now query:

var query = PFQuery(className:"currentUploads")
        query.whereKey("objectId", equalTo:"ImxZwVx7L8")
        query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
            if error == nil {
                if let objects = objects as? [PFObject] {
                    for object in objects {
                        var list: AnyObject? = object.objectForKey("comments")
                        self.commentsArray = list! as! NSArray as! [String]
                        self.tableView.reloadData()
                    }

                }
            } else {
                println("\(error?.userInfo)")
            }
        }
Sign up to request clarification or add additional context in comments.

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.