Unable to show data from one view controller to another view controller after query operation in Firebase?
<p>Recently I am trying to fetch data from Firebase and sending it to show another view controller's table view. But I have been failed due to bad handling of AsyncTask. Please suggest/show me the way how to solve this problem.</p>

<p>Here is my table in Firebase <a href="https://paste.ubuntu.com/23438022/" rel="nofollow noreferrer">here</a>. I want to get hotel name whose location is 'uttara'. </p>

<p>I tried a lot with googling but it does not work rightly. I am sure about my wrong placement AsyncTask and closure.</p>

<pre><code>@IBAction func SearchActionInitiated(sender: UIButton)
    {   
        dataTransfer(){ () -&gt; () in

            self.performSegueWithIdentifier("SearchResultPage", sender: self )

        }
    }

    func dataTransfer(completed: backgroundTaskCompleted){

        let BASE_URL_HotelLocation = "https://**************.firebaseio.com/Niloy"

        let ref = FIRDatabase.database().referenceFromURL(BASE_URL_HotelLocation)

        ref.queryOrderedByChild("location").queryStartingAtValue("uttara").observeEventType(.Value, withBlock: { snapshot in

            if let result = snapshot.children.allObjects as? [FIRDataSnapshot] {

                for child in result {

                    let downloadURL = child.value!["image"] as! String;

                    self.storage.referenceForURL(downloadURL).dataWithMaxSize(25 * 1024 * 1024, completion: { (data, error) -&gt; Void in
                        let downloadImage = UIImage(data: data!)

                        let h = Hotel()


                        h.name = child.value!["name"] as! String
                        print("Object \(count) : ",h.name)
                        h.deal = child.value!["deal"] as! String
                        h.description = child.value!["description"] as! String
                        h.distance = child.value!["distance"] as! String
                        h.latestBooking = child.value!["latestBooking"] as! String
                        h.location = child.value!["location"] as! String
                        h.image = downloadImage!

                        self.HotelObjectArray.append(h)

                        dispatch_async(dispatch_get_main_queue(), {
                                completed();
                        });


                    })

                }          

            }
            else {
                print("no results")
            }

            })
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if (segue.identifier == "SearchResultPage")
        {
            let vc = segue.destinationViewController as! SearchResultPage
           vc.arrayOfobject = HotelObjectArray
        }
 }
</code></pre>

<p>Where <code>backgroundTaskCompleted</code> is a closure.</p>