I've been developing a photo storage app that gets the image links from my Firebase database, stores them in an array in order, and then run through that array getting the images from the corresponding Firebase storage using the links in the array.
However, the function getData loads the images out of order even though the code runs through the links in order. I am not sure why this is happening although my initial thought was that the images load in order of size/which takes the least time to load. Here's my code.
for link in Constants.officialLinksArray {
let storage = Storage.storage().reference(forURL: link)
// Download the data, assuming a max size of 1MB (you can change this as necessary)
storage.getData(maxSize: 10 * 1024 * 1024) { (data, error) -> Void in
// Create a UIImage, add it to the array
if let error = error {
print(error)
} else {
//print(self.imageCount)
let loadedImage = UIImage(data: data!)
self.photoArray.append(loadedImage!)
Constants.officialPhotoArray = self.photoArray
self.buttonArray.append(self.photoArray.count)
self.collectionView.reloadData()
//print(self.photoArray)
}
}
}
Any help is appreciated. Thanks!