0
votes

I get the Error : Cannot convert value of type '([PFObject]?, NSError?) -> Void' to expected argument type '([PFObject]?, Error?) -> Void?

The Code that is causing this error is found Below.

findUser.findObjectsInBackgroundWithBlock {
        (objects:[PFObject]?, error:NSError?) -> Void in
        if error == nil{
            let user:PFUser = (objects as NSArray).lastObject as PFUser
            cell.usernameLabel.text = user.username

            UIView.animateWithDuration(0.5, animations: {
                cell.typeOfPartyLabel.alpha = 1
                cell.timeOfPartyLabel.alpha = 1
                cell.usernameLabel.alpha = 1
            })
        }
    }


    return cell
}

I have been stuck with this error for the past few days and I can't seem to locate a working solution on I found was to switch anyObject with PFObject which I did but I was getting the same error. I'm trying to query the userName and display it in a UITableView Cell.

Thank you

1

1 Answers

0
votes

This is where the meat of the error message lies:

Cannot convert value of type '([PFObject]?, NSError?) -> Void' to expected argument type '([PFObject]?, Error?) -> Void?

Swift 3.0 introduced the Error protocol, which is what is catching you here.

Try the following change and see if it resolves your problem:

findUser.findObjectsInBackgroundWithBlock {
        (objects:[PFObject]?, error: Error?) -> Void in // Changes NSError to Error
        if error == nil{
            let user:PFUser = (objects as NSArray).lastObject as PFUser
            cell.usernameLabel.text = user.username

            UIView.animateWithDuration(0.5, animations: {
                cell.typeOfPartyLabel.alpha = 1
                cell.timeOfPartyLabel.alpha = 1
                cell.usernameLabel.alpha = 1
            })
        }
    }


    return cell
}