code :
for x in 0 …< data1.count {
let cool = data1[x].photoUrl?[0] as AnyObject?
let convertString = cool as! NSString
let stringData = convertString.data(using: String.Encoding.utf8.rawValue)
let imageData = UIImage(data:stringData)
print(imageData as Any)
photoArray.append(imageData as AnyObject)
}
print(photoArray)
What I’m trying to do:
data1.photoUrl = my array that consists of string urls that are images. I am looping through each string and put them into an object called cool. I’m converting that object into a NSString.
From there I’m converting that string in data and i want to convert that data to a uiimage.
swift is giving me this error. “Value of optional type ‘Data?’ not unwrapped; did you mean to use ‘!’ or ‘?’?” but when i do that it produces nil in my console log. how can i use ? instead of ! and also how can i convert my data to uiimage so i can put it into my table cell image view.