1
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in

        if error == nil {
            if let objects = objects as? [PFObject] {
                for object in objects {
                    print("woot")
                }
            }

        } else {
            // Log details of the failure
            print("Error: \(error) \(error!.userInfo)")
        }
        dispatch_async(dispatch_get_main_queue()){
            //reload the table view

            query.cachePolicy = PFCachePolicy.NetworkElseCache
        }

    }

For some reason, the line:

query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in

is giving me the error:

Cannot convert value of type '([AnyObject]?, NSError?) -> void to expected argument type 'PFQueryArrayResultBlock?'

I have no idea how to fix the error.

Thanks!

kRiZ
  • 2,320
  • 4
  • 28
  • 39
user1990406
  • 519
  • 4
  • 16

3 Answers3

0

The result block should be like the following:

query.findObjectsInBackgroundWithBlock {
    (objects: [PFObject]?, error: NSError?) -> Void in

    if error == nil {
        if let objects = objects as? [PFObject] {
            for object in objects {
                print("woot")
            }
        }

    } else {
        // Log details of the failure
        print("Error: \(error) \(error!.userInfo)")
    }
    dispatch_async(dispatch_get_main_queue()){
        //reload the table view

        query.cachePolicy = PFCachePolicy.NetworkElseCache
    }
}

See Parse docs on querying.

kRiZ
  • 2,320
  • 4
  • 28
  • 39
0

Change 'AnyObject' to 'PFObject' in the first line. Parse v1.9.0 changed the PFObject fetch functions to be compatible with iOS 9 / Swift 2 (https://parse.com/docs/downloads).

You'll then not have to cast 'as? [PFObject]' in line 4.

0

Parse no longer uses AnyObject for Swift 2.0. So for your code change:

query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in

to

query.findObjectsInBackgroundWithBlock { (objects:[PFObject]?, error:NSError?) -> Void in

and since you no longer need to cast objects as a PFObject you can shorten it to:

if error == nil {
         for object in objects! {
                print("woot")
         }
    } else {...

Hope this helped!

Azellius
  • 41
  • 1
  • 5