title: 'NSRangeException': row (1) beyond bounds (1) for section (0)
body: <p>I have a chat Application in which messages are being fetched and updated in my tablview using NSFetchResultsController.
  Here is my code: </p>
  
  <pre><code>func controllerDidChangeContent(_ controller: NSFetchedResultsController&lt;NSFetchRequestResult&gt;)
      {
          self.tblViewChatLog.endUpdates()
          scrollToBottom(animated: true)
  
          if self.fetchedResultsController.fetchedObjects?.count == 0 {
          }
          else {
          }
      }
  
      func scrollToBottom(animated: Bool)
      {
          DispatchQueue.main.asyncAfter(deadline: .now() + 0.1)
          {
              let secCount = self.tblViewChatLog.numberOfSections
              if secCount &gt; 0
              {
                  let sections = self.fetchedResultsController.sections
                  let secInfo = sections?.last
  
                  let rows = secInfo?.objects //secInfo?.numberOfObjects
                  if (rows?.count)! &gt; 0
                  {
                      let indexPath = NSIndexPath(row: (rows?.count)!-1, section: secCount-1)
                      self.tblViewChatLog.scrollToRow(at: indexPath as IndexPath, at: .bottom, animated: animated)
                      self.view.updateConstraintsIfNeeded()
                      self.tblViewChatLog.updateConstraintsIfNeeded()
                  }
              }
          }
      }
  </code></pre>
  
  <p>I'm getting following error while trying to update my table.</p>
  
  <p><code>Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (1) beyond bounds (1) for section (0).'
  *** First throw call stack:
  (0x21f15b0b 0x216d2dff 0x21f15a51 0x2672a9c1 0x2672a45f 0x13e7b4 0x54e90 0x19adba7 0x19b78e9 0x19adb93 0x19c156d 0x19afb43 0x19b2157 0x21ed7755 0x21ed5c4f 0x21e241c9 0x21e23fbd 0x23440af9 0x2655c435 0xcc554 0x21ad0873)
  libc++abi.dylib: terminating with uncaught exception of type NSException</code></p>