[英]swift array Cannot convert value of type 'AnyObject' to expected argument type @noescape(AnyObject) throws - > Bool
[英]PFObject subclass gets “Cannot convert value of type 'Match' to expected argument type '@noescape (AnyObject) throws -> Bool'” error
在PFObject子類的數組上調用indexOf時,出現以下錯誤。
無法將“匹配”類型的值轉換為預期的參數類型“ @noescape(AnyObject)引發-> Bool”
我的課:
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並符合該擴展名。 所以我很茫然...
任何指針贊賞
找到了解決方案。 事實證明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 }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.