
[英]Anonymous closure can not be used inside a closure that has explicit arguments
[英]Anonymous closure arguments cannot be used inside a closure that has explicit argument
我对Swift相对较新,并且仍然掌握了闭包的概念。 我已经阅读过这篇文章( 匿名闭包不能在具有显式参数的闭包内使用 )。 但是,答案是将过滤器从()更改为{},但我不知道如何将其实现到我的函数中。
<<< ImageRow()
{
$0.tag = "Image"
$0.title = "Choose your profile pic"
if let tutorPic = currentuser!.objectForKey("ProfPhoto") as! PFFile!
{
tutorPic.getDataInBackgroundWithBlock({(imageData:NSData?,error:NSError?)->Void in
if(error == nil)
{
let image = UIImage(data: imageData!)
print("YOOWAHH")
print(image)
print("***********")
self.imagez = image
print(self.imagez)
$0.value = imagez
}
})
}
}
错误在$0.value = imagez
。
我从Parse下载了图像数据,并希望将其设置为我的表单的默认值。但是编译器说我已经有了显式参数,所以它不知道如何引用表单的参数。我该怎么解决这个问题?
问题在于因为每个块都是单独处理以进行调度等,所以它不知道如何正确地将引用返回到$0
的另一个块。 无论您是否明确定义了封闭块,编译器都会假设当您说$0
时,这就是您所说的块。
要解决这个问题,只需在你的顶部块中说: let myButton = $0
,然后在封闭块中引用myButton
。
将来,如果你不知道块的形式应该是什么,只需重新写出函数调用,自动完成将带回其余的块格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.