在Swift 4.2中使用SDWebimage在单元格中设置图像时,编译器会引发以下警告。
快速编译器警告:
使用'!'这里已弃用,并将在以后的版本中删除
let url = NSURL(string: (str_url) as String)
cell.img!.sd_setImage(with: url as URL!, completed: block_image) //--- WARNING ON THIS LINE AT URL!
有什么建议吗?
答案 0 :(得分:0)
使用此代码:cell. img!.sd_setImage(with: url! as URL, completed: block_image)
建议:使用URL
代替NSURL
let url = URL(string: "" ) //use url String
cell.img!.sd_setImage(with: url, completed: block_image)
答案 1 :(得分:0)
尝试一下:
if let url = URL(string: str_url) {
cell.img!.sd_setImage(with: url, completed: block_image)
}