Swift 无法调用';getDataInBackground';具有类型为';((NSData?,NSError?)->;无效)错误
我收到以下错误:Swift 无法调用';getDataInBackground';具有类型为';((NSData?,NSError?)->;无效)错误,swift,parsekit,Swift,Parsekit,我收到以下错误:无法使用类型为“((NSData?,NSError?->Void)”的参数列表调用“getDataInBackground” 我找到了,但正如你所看到的,代码对我不起作用,这里是我的代码: import UIKit import Parse . . . func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { var cell: r
无法使用类型为“((NSData?,NSError?->Void)”的参数列表调用“getDataInBackground”
我找到了,但正如你所看到的,代码对我不起作用,这里是我的代码:
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
名称以大写字母(resultcell
)开头