解析"Get Data In Background With Block"无法解决的错误



我不知道这是用户错误还是由于Xcode和Swift的更新。我正在从Parse中提取图像文件,无论我如何调整语法,我都会得到一个持久的错误:

swift:64:23:无法使用类型为'((NSData!,NSError?)->Void)的参数列表

我的代码是:

func callData() {
var imageQuery = PFObject(className: "QuestionMaster")
let iconImageFile = imageQuery["questionImage"] as! PFFile!
iconImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError?) -> Void in
if (error == nil) {
self.icon1 = UIImage(data: imageData[0])
self.icon2 = UIImage(data: imageData[1])
self.icon3 = UIImage(data: imageData[2])
self.icon4 = UIImage(data: imageData[3])
self.icon5 = UIImage(data: imageData[4])
self.icon6 = UIImage(data: imageData[5])
self.icon7 = UIImage(data: imageData[6])
self.icon8 = UIImage(data: imageData[7])
self.icon9 = UIImage(data: imageData[8])
}
else {
NSLog("Something went wrong.")
}

我一直直接从Parse文档开始工作。我也试过:

iconImageFile.getDataInBackgroundWithBlock(imageQuery, block: {
(imageData: NSData!, error: NSError?) -> Void in

我已经交换了!?,但都没有用。在我的findObjectInBackgroundWithBlock代码的其他地方也会发生同样的事情。

这是由于swift 1.2中的更改。Parse应该已经提供了一个修复这个问题的框架版本。从他们的网站下载。

编辑

另外,不要忘记使用if let打开imageData值

以下代码适用于我使用swift 1.2 的最新Parse框架版本

imageFile.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in
if let imageData = imageData where error == nil
{
self.image = UIImage(data: imageData)
}
}

相关内容

最新更新