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({

Palash Sharma
  • 662
  • 1
  • 10
  • 18
  • 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 http://stackoverflow.com/questions/26557581/command-failed-due-to-signal-segmentation-fault-11 ). 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 – Kumuluzz Sep 22 '15 at 06:38

1 Answers1

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

Santhosh
  • 691
  • 4
  • 12
  • 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]` – Palash Sharma Sep 25 '15 at 01:43
  • 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`. – Santhosh Sep 25 '15 at 01:46