I'm trying to get search results to display on a tableView. I believe I have correctly parsed the JSON, the only problem is that the results won't display on my tableView.
Here is the code:
var searchText : String! {
        didSet {
            getSearchResults(searchText)
        }
    }
    var itemsArray = [[String:AnyObject]]()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.reloadData()
    }
    // MARK: - Get data
    func getSearchResults(text: String) {
        if let excapedText = text.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) {
            Alamofire.request(.GET, "https://api.duckduckgo.com/?q=\(excapedText)&format=json")
                .responseJSON { response in
                    guard response.result.error == nil else {
                        // got an error in getting the data, need to handle it
                        print("error \(response.result.error!)")
                        return
                    }
                    let items = JSON(response.result.value!)
                    if let relatedTopics = items["RelatedTopics"].arrayObject {
                        self.itemsArray = relatedTopics as! [[String:AnyObject]]
                    }
                    if self.itemsArray.count > 0 {
                        self.tableView.reloadData()
                    }
            }
        }
    }
    // MARK: - Table view data source
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 6 // itemsArray.count
    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("SearchResultCell", forIndexPath: indexPath) as! SearchResultCell
        if itemsArray.count > 0 {
            var dict = itemsArray[indexPath.row]
            cell.resultLabel?.text = dict["Text"] as? String
        } else {
            print("Results not loaded yet")
        }
        return cell
    }
If I had a static API request I think this code would work because I could fetch in the viewDidLoad and avoid a lot of the .isEmpty checks.
When I run the program I get 6 Results not loaded yet (from my print in cellForRowAtIndexPath).  
When the completion handler is called response in, it goes down to self.items.count > 3 (which passes) then hits self.tableView.reloadData() which does nothing (I checked by putting a breakpoint on it).
What is the problem with my code?
Edit
 if self.itemsArray.count > 0 {
                        dispatch_async(dispatch_get_main_queue(), { () -> Void in
                            self.tableView.reloadData()
                        })
                    }
Tried this but the tableView still did not reload even though its reloading 6 times before the alamofire hander is called...
Here is the strange thing, obviously before the hander is called my itemsArray.count is going to be 0 so that's why I get Results not loaded yet.  I figured out why it repeats 6 times though; I set it in numberOfRowsInSection...  So @Rob, I can't check dict["Text"] or cell.resultLabel?.text because they're never getting called. "Text" is correct though, here is the link to the JSON: http://api.duckduckgo.com/?q=DuckDuckGo&format=json&pretty=1
Also, I do have the label linked up to a custom cell class SearchResultCell
Lastly, I am getting visible results.






Alamofire.requestcompletion closures are called on the main thread anyway, so that shouldn't be a problem unless you are configuring Alamofire otherwise. (All UI changes must be performed on the main thread)Text; or (c) the constraints in the cell are such that the changing of the label contents are not visible. It's impossible to diagnose until Wesley shares more debugging details.cellForRowAtIndexPath)." Well, you should get those. The table is loaded twice, once when first loaded, and again when you perform the query. The first time around you will get six "not loaded yet". The second time around it should be populating the cells.