PFObject 子类出现 "Cannot convert value of type 'Match' 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 的子class 数组上调用 indexOf 时出现以下错误。
Cannot convert value of type 'Match' to expected argument type
'@noescape (AnyObject) throws -> Bool'
我的class:
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 returns [AnyObject] 上的对象方法,所以我需要将它转换为 [Match]
let objects = self?.matchesController.objects as! [PFObject]
然后就可以了...
我在 swift 和 Parse 方面还是新手,但这对于 return [AnyObject] 的对象方法来说似乎是错误的?特别是考虑到文档中的评论
/*!
@abstract The array of instances of <PFObject> that is used as a data source.
*/
public var objects: [AnyObject]? { get }
在 PFObject 的子class 数组上调用 indexOf 时出现以下错误。
Cannot convert value of type 'Match' to expected argument type '@noescape (AnyObject) throws -> Bool'
我的class:
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 returns [AnyObject] 上的对象方法,所以我需要将它转换为 [Match]
let objects = self?.matchesController.objects as! [PFObject]
然后就可以了...
我在 swift 和 Parse 方面还是新手,但这对于 return [AnyObject] 的对象方法来说似乎是错误的?特别是考虑到文档中的评论
/*! @abstract The array of instances of <PFObject> that is used as a data source. */ public var objects: [AnyObject]? { get }