I build a webservis that requesting image url from the database. And I want to show it on the swift. But I'm gettig this error on the var photo line:
Cannot convert value of type 'subSequence' (aka 'String.CharacterView') to type 'String' in collection
let requestResponse = self.sendToServer(postUrl: "localhost",data:"abc")
let Seperated = requestResponse.characters.split(separator: " ")
var photo = Seperated[0] as String
let imageURL = URL(string: photo)
if let imageData = try? Data(contentsOf: imageURL!) {
...
}
Consider something like this:
let requestResponse = "some string"
let separated = requestResponse.characters.split(separator: " ")
if let some = separated.first {
let value = String(some)
// Output: "some"
}
The easiest solution.
let separated = requestResponse.characters.split(separator: " ").map { String($0) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With