title: How to make UITextField behave like a UISearchBar in Swift?
body: <p>I am working on an new App using UITableView and a UISearchBar in Swift and it's already working fine. But since the final project must have a complete customized searchbar, I had to move to UITextField as the input Outlet because of the customization possibilities.</p>
  <p>The problem is that I just can't figure out how to code so that the UITextField behaves like a UISearchBar. Have no idea of how I could filter the UITextField inputs and make the string usable with the UISearchBarDelegate methods.</p>
  <p>So anyone could help me out with this?</p>
  <p>EDIT: I followed Daniel's help and came up with this code, but it is returning &quot;nil&quot;, not working.</p>
  <pre><code>class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate {
  
  @IBOutlet weak var txtSearchBar: UITextField!
  var searchTxt = &quot;&quot;
  let prods = [&quot;água&quot;, &quot;terra&quot;, &quot;ar&quot;, &quot;fogo&quot;]
  var searchResults:[String] = []
  
  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
      
      txtSearchBar.delegate = self
  }
  
  
  func textFieldDidEndEditing(textField: UITextField) {
      searchTxt = textField.text
      println(searchTxt)
      searchResults = prods.filter({(produtos:String) -&gt; Bool in
          
          let nameMatch = produtos.rangeOfString(self.searchTxt, options: NSStringCompareOptions.CaseInsensitiveSearch)
          
          println(nameMatch)
          return nameMatch != nil})
  }
  </code></pre>
  <p>My input was the letters &quot;ar&quot; but it returned &quot;nil&quot;, when it shouldn't since one of the array's object is &quot;ar&quot;.</p>