0

I've a parse.com query written in swift but it doesn't let the whole project run but without it everything is fine. The error I get is Command failed due to signal: Segmentation fault: 11. The query is below:

Code

        let ObjectIDQuery = PFQuery(className: "Restaurants")
        ObjectIDQuery.whereKey("City", equalTo: CityName)
        ObjectIDQuery.orderByDescending("RN")
        ObjectIDQuery.findObjectsInBackgroundWithBlock({
            (objectsArray: [AnyObject]?, error: NSError?) -> Void in

            var ObjectIDS = objectsArray as! [PFObject]
            for i in 0..<ObjectIDS.count{
                self.name.append(ObjectIDS[i].valueForKey("Name") as! String)
                self.rating.append(ObjectIDS[i].valueForKey("Rating") as! String)
                self.phone.append(ObjectIDS[i].valueForKey("Number") as! String)
                self.url.append(ObjectIDS[i].valueForKey("Website") as! String)
                self.anp.append(ObjectIDS[i].valueForKey("ANP") as! String)
                self.image.append(ObjectIDS[i].valueForKey("Image") as! String)

                self.tableView.reloadData()

            }
        })

Please help

Edit: I have found out the problem lies in ObjectIDQuery.findObjectsInBackgroundWithBlock({

1
  • Your code works fine (thought you should make some optimisations to make it more readable and following Swift conventions). This error can be caused by many different things ( fx stackoverflow.com/questions/26557581/… ). Try to remove some recent changes you have made to the project and see if you can compile it again. Otherwise try to update your question with more code and your logs Commented Sep 22, 2015 at 6:38

1 Answer 1

2

If you are using the latest Parse SDK and Swift 2, the method signature for PFQuery.findObjectsInBackgroundWithBlock has changed. Refer: https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/issues/280

Replace (objectsArray: [AnyObject]?, error: NSError?) -> Void in with (objectsArray: [PFObject]?, error: NSError?) -> Void in

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

2 Comments

Hi, Thanks for the help. Nut now I'm getting this error Downcast from '[PFObject]?' to '[PFObject]' only unwraps optionals; did you mean to use '!'? on the line var ObjectIDS = objectsArray as? [PFObject]
Since objectsArray is already a [PFObject] you do not need to downcast it. Replace var ObjectIDS = objectsArray as! [PFObject] with var ObjectIDS = objectsArray!. But before using this make sure your objectsArray is not empty by using objectsArray.count != 0.

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.