Using '!' here is deprecated and will be r

2020-02-06 17:03发布

Compiler throwing following warning when setting image in a cell using SDWebimage in Swift 4.2.

Swift Compiler warning :

Using '!' here is deprecated and will be removed in a future release

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!

Any Suggestions ?

2条回答
2楼-- · 2020-02-06 17:32

Use this code : cell. img!.sd_setImage(with: url! as URL, completed: block_image)

Suggestion: use URL instead of NSURL

            let url = URL(string: "" ) //use url String
            cell.img!.sd_setImage(with: url, completed: block_image)
查看更多
放我归山
3楼-- · 2020-02-06 17:50

Try this:

if let url = URL(string: str_url) {
    cell.img!.sd_setImage(with: url, completed: block_image)
}
查看更多
登录 后发表回答