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

大城市里の小女人 提交于 2019-12-17 21:29:19

问题


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 ?


回答1:


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)



回答2:


Try this:

if let url = URL(string: str_url) {
    cell.img!.sd_setImage(with: url, completed: block_image)
}


来源:https://stackoverflow.com/questions/52491298/using-here-is-deprecated-and-will-be-removed-in-a-future-release-swift-4-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!