I tried to download several image from itunes api using asynchronous request, I already stored the image url on array. But when I download the image and put it on new array the images order become random.
Here is my code:
for appDict in appArray {
let songCoverUrl: String? = appDict["im:image"][0]["label"].string
let largerImageUrl = songCoverUrl!.stringByReplacingOccurrencesOfString("55x55", withString: "400x400")
if largerImageUrl.isEmpty == false {
let url : NSURL = NSURL(string: largerImageUrl)!
let request : NSURLRequest = NSURLRequest(URL: url)
NSURLSession.sharedSession().dataTaskWithRequest(request){ (imagedata:NSData?, response:NSURLResponse?, error:NSError?) -> Void in
if error == nil {
let image : UIImage = UIImage(data: imagedata!)!
self.coverArray.append(image)
}else{
let image : UIImage = UIImage(named: "noArtworkImage.png")!
self.coverArray.append(image)
}
}.resume()
}
}
How can I keep the order of the images as the array of url?