【发布时间】:2017-04-13 05:25:30
【问题描述】:
我在 swift 的前一阶段使用 if let 循环,但在更新版本中,我无法使用相同的循环。我尝试使用guard let,但它也不起作用。
let imageArray = dataObject?["image"] as! NSArray
if let image = imageArray[0]{
let imageURL = "compute.amazonaws.com/" + "\(image)"
print(imageURL)
if let url: URL = URL(string:"\(imageURL)")!{
let task = URLSession.shared.dataTask(with: url, completionHandler: { (responseData, responseUrl, error) -> Void in
if let data = responseData{
DispatchQueue.main.async(execute: { () -> Void in
cell?.imageViewProduct.image = UIImage(data: data)
})
}
})
task.resume()
}
}
我的图像,即 imageArray[0] 是可选值。在某些情况下,它可能不是从后端提供的,所以我想使用 if let 或类似的。
【问题讨论】:
-
图片的类型是什么?
-
问题是什么?
-
图片类型为一半 URL 其余部分由我提供。
-
@VladHatko 问题是如果让它显示错误,我将无法使用:条件绑定的初始化程序必须具有可选类型而不是任何
-
我的回答能解决问题吗?