title: When should I reloadData()?
body: <p>I'm switching an existing app to an MVC architecture. I have a Search class which handles data modelling and I have the following function in it:</p>
  
  <pre><code>     func performSearch(searchTerm: String){
      let session = NSURLSession.sharedSession()
      let task = session.dataTaskWithURL(urlForQuery(searchTerm)!, completionHandler: { (data: NSData!, response: NSURLResponse!, error: NSError!) -&gt; Void in
          if (error != nil) {
              println(error.localizedDescription)
          }
          var err: NSError?
          let result: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options:NSJSONReadingOptions.MutableContainers, error: &amp;err) as NSDictionary
          if (err != nil) {
              println(err!.localizedDescription)
          }
          let results: NSMutableArray? = result.objectForKey("results") as? NSMutableArray
  
              if let testVar = results {
                  // Uncomment this to print all feeds
                   println(testVar)
                  self.searchedPodcasts.removeAllObjects()
                  self.searchedPodcasts.addObjectsFromArray(testVar)
              }
  
      })
      task.resume()
  
  }
  </code></pre>
  
  <p>This basically queries the iTunes api and returns an Array (searchedPodcasts) of results. When these objects are added to the array, I would like to use reloadData() in my tableView. I understand it would be bad practice to call something like TableViewController.tableView!.reloadData() within this function, but how can I do it once objects have been added to the array?</p>
  
  <p>I have a sort of workaround which I'm not happy with in my TableViewController class:</p>
  
  <pre><code>    func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
      println("text did change")
      let length = countElements(searchText)
      if (length &lt;= 3) {
          searchModel.resetSearch()
          searchTableView.reloadData()
      } else if (length &gt; 3) {
      searchModel.performSearch(searchText)
      searchTableView.reloadData()
      }
  }
  </code></pre>
  
  <p>This reloads the table view fine, but only when textDidChange is called on the searchBar, which means that once the array has had objects added to it, you need to add/remove a character in the searchBar to call reloadData(). What is a good way to solve this problem?</p>
  
  <p>Thanks!</p>