0

Heres a copy of my code where the error is giving me, the error is on the line where it says query.findobjectsInBackgroundWithBlock. The full error message is this: `Cannot convert value type ([AnyObject]!, NSError!) -> Void to expected argument type 'PFQueryArrayResultBlock?'

// Retrieve Messages
func retrieveMessages() {

    // Create a new PFQuery
    var query:PFQuery = PFQuery(className: "Message")

    // Call findobjectsinbackground
    query.findObjectsInBackgroundWithBlock {(objects:[AnyObject]!, error:NSError!) -> Void in

    // Clear the messagesArray

        self.messageArray = [String]()
        // Loops through the objects
    for messageObject in objects {

        // Retrieve the text column value of each PFObject
        let messageText:String? = (messageObject as! PFObject)["Text"] as? String
        // Assign it into our messagesArray
        if messageText != nil {
            self.messageArray.append(messageText!)
        }
    }
        // Reload the tableview
    self.messageTableView.reloadData()
    }
}
1
  • 1
    are you sure that ([AnyObject]!, NSError!) -> Void is the right signature for the block? I would look up PFQueryArrayResultBlock and copy that declaration... Commented Nov 23, 2015 at 19:14

1 Answer 1

0

The method signature had improved in Swift 2.0 with Parse SDK 1.10.0. Replace [AnyObject]! with [PFObject]?. [PFObject] is an optional because Swift doesn't know if it will exist or not.

func retrieveMessages() {

var query:PFQuery = PFQuery(className: "Message")

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

    self.messageArray = [String]()

    for messageObject in objects {

        let messageText:String? = (messageObject as! PFObject)["Text"] as? String

        if messageText != nil {
            self.messageArray.append(messageText!)
        }
    }

    self.messageTableView.reloadData()
}
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.