我收到以下错误: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 3+中避免这些问题
self.resultsImageFiles[indexPath.row].getDataInBackground { (imageData, error) in
在Swift 3+中NSData
被替换为Data
和NSError
与Error
或者注释掉该行,重新键入它并使用代码完成。
除了这个问题,你不鼓励在cellForRow
中运行非托管异步任务,因为可以立即释放单元格。
并且 - 因为你是swift的新手 - 请遵守struct
和class
名称以大写字母(ResultsCell
)开头的命名惯例。