 // MARK: - UISearchBarDelegate
 extension SearchViewController: UISearchBarDelegate {
     func searchBarSearchButtonClicked(searchBar: UISearchBar) {
+        performSearch()
+    }
+    
+    func performSearch() {
         if !searchBar.text!.isEmpty {
             searchBar.resignFirstResponder()
         

    
    // MARK: - action
    @IBAction func segmentChanged(sender: UISegmentedControl) {
        print("Segment changed: \(sender.selectedSegmentIndex)")
    }
    
}

            hasSearched = true
            searchResults = [SearchResult]()
        
            let url = urlWithSearchText(searchBar.text!, categoary: segmentControl.selectedSegmentIndex)
            let session = NSURLSession.sharedSession()
            dataTask = session.dataTaskWithURL(url, completionHandler: {
                (data, response, error)  in
