Carlos
Carlos

Reputation: 1

Xcode 7 Error Code "Cannot convert value type([AnyObject]

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()
    }
}

Upvotes: 0

Views: 1358

Answers (1)

Edison
Edison

Reputation: 11987

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()
}
}

Upvotes: 0

Related Questions