首页 > 解决方案 > 将字符串更改为有效的 url swift

问题描述

嗨,我想从源接收图像,但我意识到它有一些字符会在 swift Urlsession 上返回 nil 我想知道如何更改此 url

https://melovaz.net/wp-content/uploads/2019/12/¡Viva-Latino-2.jpg _

https://melovaz.net/wp-content/uploads/2019/12/%C2%A1Viva-Latino-2.jpg

使用swift所以我可以下载图片谢谢

标签: swiftalamofirensurlsession

解决方案


感谢这篇文章这篇文章

我应该使用

var urlString = originalString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)

推荐阅读