Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 我希望将图像名称作为字符串与URL连接起来,并希望显示在UIImageView中_Swift_String Concatenation - Fatal编程技术网

Swift 我希望将图像名称作为字符串与URL连接起来,并希望显示在UIImageView中

Swift 我希望将图像名称作为字符串与URL连接起来,并希望显示在UIImageView中,swift,string-concatenation,Swift,String Concatenation,我试图将图像名称作为字符串与URL连接起来,还想在UIImageView中显示该图像,但没有得到任何简单的解决方案 let vc1 = baseUrl + passport self.passportImg.sd_setImage(with: URL(string:"\(vc1)")) URL不是一个字符串,它是结构化的。 您不应该只使用String串联来串联它,您应该为它使用适当的方法: let baseURL: URL = … // your url let passport: Strin

我试图将图像名称作为字符串与
URL
连接起来,还想在
UIImageView
中显示该图像,但没有得到任何简单的解决方案

let vc1 = baseUrl + passport
self.passportImg.sd_setImage(with: URL(string:"\(vc1)"))

URL
不是一个
字符串,它是结构化的。
您不应该只使用
String
串联来串联它,您应该为它使用适当的方法:

let baseURL: URL = … // your url
let passport: String = "passport" // path to passport
let vc1 = baseURL.appendingPathComponent(passport) // it is still `URL`
self.passportImg.sd_setImage(with: vc1)