无法使用类型'((NSData?,NSError?) - > Void)的参数列表调用'getDataInBackground'错误

问题描述 投票:-1回答:1

我收到以下错误:Cannot invoke 'getDataInBackground' with an argument list of type '((NSData?, NSError?) -> Void)'

我找到了similar question,但是你可以看到代码对我不起作用,这里是我的代码:

import UIKit
import Parse
.
.
.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell: resultsCell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! resultsCell
    cell.usernameLbl.text = self.resultsUsernameArray[indexPath.row]
    cell.profileNameLbl.text = self.resultsProfileNameArray[indexPath.row]   
    //here error in line below:  
    self.resultsImageFiles[indexPath.row].getDataInBackground { (imageData: NSData?, error: NSError?) -> Void in   
        if error == nil{
            let image = UIImage(data: imageData)
            cell.profileImg.image = image
        }

    }
    return cell
}
swift parsekit
1个回答
1
投票

如果只是省略闭包中的类型,可以在Swift 3+中避免这些问题

self.resultsImageFiles[indexPath.row].getDataInBackground { (imageData, error) in

在Swift 3+中NSData被替换为DataNSErrorError

或者注释掉该行,重新键入它并使用代码完成。

除了这个问题,你不鼓励在cellForRow中运行非托管异步任务,因为可以立即释放单元格。

并且 - 因为你是swift的新手 - 请遵守structclass名称以大写字母(ResultsCell)开头的命名惯例。

© www.soinside.com 2019 - 2024. All rights reserved.