在PFObject的子类数组上调用indexOf时出现以下错误。
无法将“匹配”类型的值转换为预期的参数类型 '@noescape(AnyObject)抛出 - >布尔“
我的班级:
class Match: PFObject, PFSubclassing {XXXX}
发生错误的方法:
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
}
}
}
}
从我只读的内容来看,当数组中包含的对象不符合Equatable扩展时,会发生此错误。但是PFObject继承了符合该扩展的NSObject。所以我不知所措......
赞赏任何指针
答案 0 :(得分:1)
找到解决方案。事实证明,PFQueryTableViewController上的objects方法返回[AnyObject],所以我需要将它转换为[Match]
let objects = self?.matchesController.objects as! [PFObject]
然后它有效......
我还是swift和Parse的新手,但对于返回[AnyObject]的对象方法来说这似乎不对?特别是考虑到文档中的评论
/*! @abstract The array of instances of <PFObject> that is used as a data source. */ public var objects: [AnyObject]? { get }