将字符串更改为有效的URL swift

问题描述 投票:0回答:1

嗨,我想从源头接收图像,但我意识到它的某些字符会在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 alamofire nsurlsession
1个回答
0
投票

感谢此帖子this post

我应该使用

var urlString = originalString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
© www.soinside.com 2019 - 2024. All rights reserved.