title: Swift 4 delegates and passing textfield data
body: <p>I am trying to make an app using the GoogleBooks API where I can use either a title or author or both to search for books. I am currently just working on the delegate portion to be able to pass the search terms to the results table view. However, I am getting errors with the variables I am using being let constants but I have them declared as var so I'm not sure where I am messing up.</p>
  
  <p>This is the UIViewController code for the view with the two search boxes and the button: </p>
  
  <pre><code>import UIKit
  
  protocol ViewControllerDelegate: class {
      func searchInput(_ titleFromSearch: String?, authorFromSearch: String?)
  }
  
  class ViewController: UIViewController {
      @IBOutlet weak var titleFromSearch: UITextField!
      @IBOutlet weak var authorFromSearch: UITextField!
  
      weak var delegate: ViewControllerDelegate?
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          titleFromSearch.delegate = self
          authorFromSearch.delegate = self
      }
  
      override func touchesEnded(_ touches: Set&lt;UITouch&gt;, with event:
          UIEvent?) {
          super.touchesEnded(touches, with: event)
          titleFromSearch.resignFirstResponder()
          authorFromSearch.resignFirstResponder()
      }
  }
  
  extension ViewController: UITextFieldDelegate {
      func fieldsDidEndEditing(_ titleEntered: UITextField, authorEntered:
          UITextField) {
          if let delegateController = delegate {
              delegateController.searchInput(titleFromSearch.text,
                                             authorFromSearch: authorFromSearch.text)
          }
      }
  }
  </code></pre>
  
  <p>And this is the code for the TableViewController that I have set up for the results to be displayed in. </p>
  
  <pre><code>import UIKit
  import GoogleBooksApiClient
  
  class SearchResultsTableViewController: UITableViewController {
      var titleFromSearch: String?
      var authorFromSearch: String?
  
      var data = [Volume]()
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          let session = URLSession.shared
          let client = GoogleBooksApiClient(session: session)
  
          let req = GoogleBooksApi.VolumeRequest.List(query: "Google")
  
          let task: URLSessionDataTask = client.invoke(
              req,
              onSuccess: { [weak self] volumes in
                  self?.data = volumes.items
                  self?.tableView.reloadData()
              },
              onError: { error in
                  print("\(error)") }
          )
          task.resume()
      }
  
      // MARK: - Table view data source
  
      override func numberOfSections(in tableView: UITableView) -&gt; Int {
          return 1
      }
  
      override func tableView(_ tableView: UITableView, numberOfRowsInSection
          section: Int) -&gt; Int {
          return data.count
      }
  
      override func tableView(_ tableView: UITableView, cellForRowAt
          indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: "Cell",
                                                   for: indexPath)
  
          let item = data[indexPath.row]
          cell.textLabel?.text = item.volumeInfo.title
          cell.detailTextLabel?.text = item.volumeInfo.authors.first
  
          return cell
      }
  
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          super.prepare(for: segue, sender: sender)
          if let destination = segue.destination as? ViewController {
              destination.delegate = self
          }
      }
  }
  </code></pre>
  
  <p>Here is where I get the let constant error is with these two assignment statements:</p>
  
  <pre><code>extension SearchResultsTableViewController: ViewControllerDelegate {
      func searchInput(_ titleFromSearch: String?, authorFromSearch: String?)
      {
          titleFromSearch = titleFromSearch
          authorFromSearch = authorFromSearch
      }
  }
  </code></pre>
  
  <p>I added all the code because as I said I am new to iOS and I'm not sure where this error stems from in the code.</p>