I have an API call GET in Swift 5 Code for fetching the Images, I am getting url of the images , I have to change the url into UIImage to append the urls to a arrayimages=UIImage, data of the url is there but it is not appending to the arrayImages. my task is to put all the data images into the collection view ,if there is another way then guide me , Thanks.
--->. let arrayImages = UIImages
guard let data = response?.data(using: .utf8) else {
return
}
do {
let jsonObj = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as! [String: Any]
if jsonObj["error"] as! Bool == false {
print("galleryResponse/\(jsonObj)")
let jsonResponse = jsonObj["response"] as! [[String: Any]]
for i in 0...jsonResponse.count-1 {
let strGalleryImage = jsonResponse[i]["Gallery_Full"] as? String
if let imgurl = strGalleryImage {
self.userImageString1 = "\(USER_IMAGE_BASE_URL)\(imgurl)"
}
var imageString1: String?
var url1: URL!
imageString1 = self.userImageString1
if let imageUrlString1 = imageString1 {
url1 = URL(string: imageUrlString1)
DispatchQueue.global().async { [weak self] in
if let data = try? Data(contentsOf: url1!){
if let imagedata = UIImage(data: data){
print("YES_IMG")
if data != nil {
DispatchQueue.main.async {
print("append_IMG")
self!.arrimages.append(imagedata)
}
}
}
}
}
}
//}
}
}
} catch {
print("Unable_to_load_data:/\(error)")
}
})
}