Search code examples
swiftparse-platformpfobject

PFObject subclass gets "Cannot convert value of type 'Match' to expected argument type '@noescape (AnyObject) throws -> Bool'" error


I'm getting the following error when calling indexOf on an array of a subclass of PFObject.

Cannot convert value of type 'Match' to expected argument type '@noescape (AnyObject) throws -> Bool'

my class:

class Match: PFObject, PFSubclassing {XXXX}

The method where the error is happening:

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
    //dismiss the image picker
    self.dismissViewControllerAnimated(true) { () -> Void in
        //wait for the dismissal in case there is an error to show
        let recordedVideofileURL = info[UIImagePickerControllerMediaURL] as? NSURL

        if let recordedVideofileURL = recordedVideofileURL
        {
            //upload the file to S3
            do
            {
                let uploadRequest = try S3UploadManager.uploadFile(self.match!.localPathToVideo()!)

                self.match!.saveEventually({ (success: Bool, error: NSError?) -> Void in
                    if (success)
                    {
                        // The object has been saved.
                        self.matchesController.loadObjects()

                        //set up progress tracking for the upload
                        uploadRequest.uploadProgress = {[weak self](bytesSent:Int64, totalBytesSent:Int64, totalBytesExpectedToSend:Int64) -> Void  in
                            if let match = self?.match
                            {
      >>>>>>error here           var index = self?.matchesController.objects?.indexOf(match)
                            }
                        }
                    }

                })
            }
            catch
            {
                // TODO: handle error
            }
        }
    }
}

From what i read only, this error happens when the object contained in the array does not conform to the Equatable extension. But PFObject inherits from NSObject which conform to that extension. So I'm at a loss...

Any pointers appreciated


Solution

  • Found the solution. It turns out that the objects method on the PFQueryTableViewController returns [AnyObject], so I need to cast it to [Match]

    let objects = self?.matchesController.objects as! [PFObject]
    

    and then it works...

    I'm still new at swift and Parse, but this seem wrong for objects method to return [AnyObject]? especially given the comment in the doc

    /*!
     @abstract The array of instances of <PFObject> that is used as a data source.
     */
    public var objects: [AnyObject]? { get }