title: Firebase Storage Async Image Download not in the right order
body: <p>I am met with a problem when I tried to download a batch of images off firebase storage. Basically, because the file sizes differ, the images are not appended to the image array properly causing the images to be in the wrong order that I wanted. Below is the code</p>
  
  <pre><code>import Foundation
  import FirebaseStorage
  
  class GalleryCellDetailedData {
      var selectedGallery:String?
      var count:Int
  
      init(selectedGallery:String?,count:Int){
          self.selectedGallery = selectedGallery
          self.count = count
      }
  
      func addImages(completion:(data:[NSData])-&gt;()){
          var datas = [NSData]()
          let myGroup = dispatch_group_create()
  
          for i in 0..&lt;count {
              dispatch_group_enter(myGroup)
              getImage(i, completion: { (image:NSData) in
                  datas.append(image)
                  print("Finish Request \(i)")
                  dispatch_group_leave(myGroup)
              })
          }
  
          dispatch_group_notify(myGroup, dispatch_get_main_queue(), {
            completion(data: datas)
          })
      }
  
      private func getImage(number:Int, completion:(image:NSData)-&gt;()){
          let storage = FIRStorage.storage()
  
          //Reference to Firebase Profile Picture Storage
          let storageRef = storage.referenceForURL("gs://mannacatering-addcb.appspot.com")
          print("Initiating Image Download")
  
          let galleryPicRef = storageRef.child("Gallery/\(selectedGallery!)/g\(String(number)).jpg")
  
          //Download Image
          galleryPicRef.dataWithMaxSize(1 * 1024 * 1024) { (data, error) -&gt; Void in
              if (error != nil) {
                  print("fail to download image")
              }
  
              dispatch_async(dispatch_get_main_queue(), {
                  print("Dispatching image")
                  completion(image:data!)
              })
          }
      }
  }
  </code></pre>
  
  <p>I split them up into 2 separate functions because I tried to manage them in a single function and the order is in a mess as well and I thought this might work but apparently not.</p>