title: Swift when clicking on table view cell it says index out of range or goes back to the home screen
body: <p>For some reason when I click on a table view cell it kicks me out of the app or says the index is out of range. The information is being passed because it is displaying the book titles in the table view cells, not sure why it isn't working. Any help would be appreciated</p>
  
  <p>The segue to connect booksearchview and inroviewcontroller is correct</p>
  
  <p>My view controller for searching for book</p>
  
  <pre><code>import UIKit
  import Foundation
  
  class ViewController: UIViewController, UITextFieldDelegate {
  
  @IBOutlet weak var bookTitleTextField: UITextField!
  @IBOutlet weak var authorTextField: UITextField!
  
  var book: String = ""
  var author: String = ""
  
  var bookCoversInfo = [UIImage]()
  var titlesInfo = [String]()
  var authorsInfo = [String]()
  var yearInfo = [String]()
  var pagesInfo = [String]()
  var starRatingInfo = [UIImage]()
  var starRatingCountInfo = [Double]()
  var reviewsInfo = [String]()
  var descriptionsInfo = [String]()
  
  override func viewDidLoad() {
      super.viewDidLoad()
      bookTitleTextField.delegate = self
      authorTextField.delegate = self
  }
  
  func textFieldShouldReturn(_ textField: UITextField) -&gt; Bool {
      bookTitleTextField.resignFirstResponder()
      authorTextField.resignFirstResponder()
      return true;
  }
  
  func initializeTextFields() {
      bookTitleTextField.delegate = self
      bookTitleTextField.keyboardType = UIKeyboardType.default
  
      authorTextField.delegate = self
      authorTextField.keyboardType = UIKeyboardType.default
  }
  
  @IBAction func searchButton(_ sender: UIButton) {
  
      var query = ""
  
      if let book = bookTitleTextField.text, let author = authorTextField.text {
          query = book
          if (!query.isEmpty) {
              query += "+"
          }
          query += "inauthor\(author)"
      }
  
      if let book = bookTitleTextField.text {
          query = book
      }
  
      if let author = authorTextField.text {
          if (!query.isEmpty) {
              query += "+"
          }
          query += "inauthor:\(author)"
      }
  
      let session: URLSession = {
          let config = URLSessionConfiguration.default
          return URLSession(configuration: config)
      }()
  
      let queryItems = [NSURLQueryItem(name: "q", value: query)]
      let urlComps = NSURLComponents(string: "https://www.googleapis.com/books/v1/volumes?")!
      urlComps.queryItems = queryItems as [URLQueryItem]
      let booksURL = urlComps.url!
  
      let request = URLRequest(url: booksURL)
  
   //   let request = URLRequest(url: urlComps.url!)
  
      let task = session.dataTask(with: request) {
          (data, response, error) -&gt; Void in
          if let jsonData = data {
              if let jsonString = try? JSONSerialization.jsonObject(with: jsonData, options: []) {
                      let arrayOfTitles = (jsonString as AnyObject).value(forKeyPath: "items.volumeInfo.title") as? [String]
                      if let items = arrayOfTitles {
                          self.titlesInfo = items
                      }
  
                      let arrayOfAuthors = (jsonString as AnyObject).value(forKeyPath: "items.volumeInfo.authors") as? [String]
                      if let itemsA = arrayOfAuthors {
                          self.authorsInfo = itemsA
                      }
  
                //  let arrayOfYear = (jsonString as AnyObject).value(forKeyPath: "items.volumeInfo.pageCount") as? [String]
                     let arrayOfPage = (jsonString as AnyObject).value(forKeyPath: "items.volumeInfo.pageCount") as? [String]
                      if let itemPages = arrayOfPage {
                          self.pagesInfo = itemPages
                      }
  
                      let arrayOfRatings = (jsonString as AnyObject).value(forKeyPath:    "items.volumeInfo.averageRating") as? [UIImage]
                      if let itemStars = arrayOfRatings {
                          self.starRatingInfo = itemStars
                      }
  
                      let arrayOfReviews = (jsonString as AnyObject).value(forKeyPath: "items.volumeInfo.ratingsCount") as? [String]
                      if let itemRating = arrayOfReviews {
                          self.reviewsInfo = itemRating
                      }
  
                      let arrayOfStarsCount = (jsonString as AnyObject).value(forKeyPath:    "items.volumeInfo.averageRating") as? [Double]
                      if let itemStarsCount = arrayOfStarsCount {
                          self.starRatingCountInfo = itemStarsCount
                      }
  
                      let arrayOfDescription = (jsonString as AnyObject).value(forKeyPath: "items.volumeInfo.description") as? [String]
                      if let itemDescription = arrayOfDescription {
                          self.descriptionsInfo = itemDescription
                      }
  
                      let arrayOfBookCover = (jsonString as AnyObject).value(forKeyPath: "items.volumeInfo.imageLinks.thumbnail") as? [UIImage]
                      if let itemCover = arrayOfBookCover {
                          self.bookCoversInfo = itemCover
                      }
  
                      DispatchQueue.main.async {
                          self.performSegue(withIdentifier: "findTitles", sender: self)
                      }
              }
          }
              else {
                  print("Error fetching books \(error.debugDescription)")
              }
          }
      task.resume()
  }
  
  override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
      bookTitleTextField.resignFirstResponder()
      authorTextField.resignFirstResponder()
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if (segue.identifier == "findTitles") {
          if let destinationVC = segue.destination as? BookSearchView {
              destinationVC.bookCoversReady = bookCoversInfo
              destinationVC.booksReady = titlesInfo
              destinationVC.authorsReady = authorsInfo
              destinationVC.yearReady = yearInfo
              destinationVC.pagesReady = pagesInfo
              destinationVC.starRatingReady = starRatingInfo
              destinationVC.starRatingCountReady = starRatingCountInfo
              destinationVC.reviewsReady = reviewsInfo
              destinationVC.descriptionsReady = descriptionsInfo
          }
      }
  }
  
  }
  </code></pre>
  
  <p>My book search where table view cells are</p>
  
  <pre><code>import UIKit
   import Foundation
  
   var myIndex = 0
  
  class BookSearchView: UITableViewController {
  
  var bookCoversReady = [UIImage]()
  var booksReady = [String]()
  var authorsReady = [String]()
  var yearReady = [String]()
  var pagesReady = [String]()
  var starRatingReady = [UIImage]()
  var starRatingCountReady = [Double]()
  var reviewsReady = [String]()
  var descriptionsReady = [String]()
  
  var bookCoversSend: UIImage?
  var titleSend: String = ""
  var authorsSend: String = ""
  var yearSend: String = ""
  var pagesSend: String = ""
  var starRatingSend: UIImage?
  var starRatingCountSend: Double = 0.0
  var reviewsSend: String = ""
  var descriptionsSend: String = ""
  
  override func viewDidLoad() {
     super.viewDidLoad()
  }
  
  override func viewDidAppear(_ animated: Bool) {
      super.viewDidAppear(animated)
      tableView.reloadData()
  }
  
  override func numberOfSections(in tableView: UITableView) -&gt; Int {
      return 2
  }
  
  override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return booksReady.count
  }
  
  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
      cell.textLabel?.text = booksReady[indexPath.row]
      cell.detailTextLabel?.text = authorsReady[indexPath.row]
      return cell
  }
  
  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
          myIndex = indexPath.row
      // bookCoversSend = bookCoversReady[indexPath.row]
           //  titleSend = booksReady[indexPath.row]
         //    authorsSend = authorsReady[indexPath.row]
         //    yearSend = yearReady[indexPath.row]
          //   pagesSend = pagesReady[indexPath.row]
          //   starRatingSend = starRatingReady[indexPath.row]
          //   starRatingCountSend = starRatingCountReady[indexPath.row]
          //   reviewsSend = reviewsReady[indexPath.row]
          //   descriptionsSend = descriptionsReady[indexPath.row]
      DispatchQueue.main.async {
          self.performSegue(withIdentifier: "bookInfo", sender: self)
      }
  }
  
  func prepareForSegue(segue: UIStoryboardSegue, sender: Any?) {
      if (segue.identifier == "bookInfo") {
          if let destinationVC = segue.destination as? InfoViewController {
              destinationVC.bookCoversDisplay = bookCoversReady
              destinationVC.titlesDisplay = booksReady
              destinationVC.authorsDisplay = authorsReady
              destinationVC.yearDisplay = yearReady
              destinationVC.pagesDisplay = pagesReady
              destinationVC.starRatingDisplay = starRatingReady
              destinationVC.starRatingNumber = starRatingCountReady
              destinationVC.reviewsDisplay = reviewsReady
              destinationVC.descriptionsDisplay = descriptionsReady
          }
      }
  }
  }
  </code></pre>
  
  <p>My info view controller for displaying book info</p>
  
  <pre><code> import UIKit
  import Foundation
  
  class InfoViewController: UIViewController {
  
  @IBOutlet var bookTitleLabel: UILabel!
  @IBOutlet var authorLabel: UILabel!
  @IBOutlet var bookYear: UILabel!
  @IBOutlet var numberOfPages: UILabel!
  @IBOutlet var totalReviews: UILabel!
  @IBOutlet var descriptionLabel: UILabel!
  @IBOutlet var bookCoverImage: UIImageView!
  @IBOutlet var ratingStars: UIImageView!
  
    var titlesDisplay = [String]()
  var authorsDisplay = [String]()
    var yearDisplay = [String]()
    var pagesDisplay = [String]()
    var starRatingNumber = [Double]()
    var reviewsDisplay = [String]()
    var descriptionsDisplay = [String]()
    var bookCoversDisplay = [UIImage]()
    var starRatingDisplay = [UIImage]()
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      bookCoverImage.image = bookCoversDisplay[myIndex]
      bookTitleLabel.text = titlesDisplay[myIndex]
      authorLabel.text = authorsDisplay[myIndex]
      bookYear.text = yearDisplay[myIndex]
      numberOfPages.text = pagesDisplay[myIndex]
      ratingStars.image = starRatingDisplay[myIndex]
      let starRating = starRatingNumber[myIndex]
      totalReviews.text = reviewsDisplay[myIndex]
      descriptionLabel.text = descriptionsDisplay[myIndex]
  
      if starRating &lt; 0.5 {
          ratingStars.image = UIImage(named: "zerostars")
      } else if starRating &gt;= 0.5 &amp;&amp; starRating &lt; 1.0 {
          ratingStars.image = UIImage(named: "halfstar")
      } else if starRating &gt;= 1.0 &amp;&amp; starRating &lt; 1.5 {
          ratingStars.image = UIImage(named: "onestar")
      } else if starRating &gt;= 1.5 &amp;&amp; starRating &lt; 2.0 {
          ratingStars.image = UIImage(named: "onehalfstar")
      } else if starRating &gt;= 2.0 &amp;&amp; starRating &lt; 2.5 {
          ratingStars.image = UIImage(named: "twostars")
      } else if starRating &gt;= 2.5 &amp;&amp; starRating &lt; 3.0 {
          ratingStars.image = UIImage(named: "twohalfstars")
      } else if starRating &gt;= 3.0 &amp;&amp; starRating &lt; 3.5 {
          ratingStars.image = UIImage(named: "threestars")
      } else if starRating &gt;= 3.5 &amp;&amp; starRating &lt; 4.0 {
          ratingStars.image = UIImage(named: "threehalfstars")
      } else if starRating &gt;= 4.0 &amp;&amp; starRating &lt; 4.5 {
          ratingStars.image = UIImage(named: "fourstars")
      } else if starRating &gt;= 4.5 &amp;&amp; starRating &lt; 5.0 {
          ratingStars.image = UIImage(named: "fourhalfstars")
      } else if starRating == 5.0 {
          ratingStars.image = UIImage(named: "fivestars")
      }
  
     //  bookCoverImage.image = bookCoversDisplay
    //   bookTitleLabel.text = titlesDisplay
    //   authorLabel.text = authorsDisplay
    //   bookYear.text = yearDisplay
    //   numberOfPages.text = pagesDisplay
    //   ratingStars.image = starRatingDisplay
    //   totalReviews.text = reviewsDisplay
    //   descriptionLabel.text = descriptionsDisplay
  
  }
  }
  </code></pre>