title: i want to insert rows as section in tableview in swift3
body: <p>I'm successfully appending data at array but <code>UITableView</code> not inserting and showing that data.</p>
  
  <p>But the following error showing</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception
    'NSInternalInconsistencyException', reason: 'attempt to insert row 4
    into section 0, but there are only 0 rows in section 0 after the
    update'</p>
  </blockquote>
  
  <p>I have tried like this :</p>
  
  <pre><code>        super.viewDidLoad()
  
      array1=["A1","B1","C1","D1"]
      array2=["A2","B2","C2","D2"]
      array3=["A3","B3","C3","D3"]
      array4=["A4","B4","C4","D4"]
      dict1=[0:array1,1:array2,3:array3,4:array4,2:names]
      print( (dict1))
      print( (dict1[1]?.count)!)
      print(dict1.keys.count)
  
  }
      public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int
  
  {
     return (((dict1)[section])!.count)
  }
  
  public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell
  {
      if tableView == tableExplore {
  
      cellMain = tableView.dequeueReusableCell(withIdentifier:"cellExp", for: indexPath) as! ExploreLocallyCell
      cellMain.textLabel?.textColor = UIColor(red: 194.0/255, green: 198.0/255, blue: 198.0/255, alpha: 1.0)
          cellMain.textLabel?.text=(dict1[indexPath.section])?[indexPath.row]
      }
      return cellMain
  
  }
   public func numberOfSections(in tableView: UITableView) -&gt; Int // Default is 1 if not implemented
  {
  
  
  return dict1.keys.count
  }
    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -&gt; String?
  {
      return (names)[section]
  
  }
  
  public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
  {
    self.insert(section:indexPath.section, row: indexPath.row)
  
  }
  func insert(section:Int,row:Int)
  {
     print(dict1[section]!)
      // Update Table Data
      tableView.beginUpdates()
   dict1[section]!.append("BAlu")
      print(dict1[section]!)
      tableView.insertRows(at: [IndexPath(row:dict1[section]!.count-1, section: section)], with: .automatic)
      tableView.endUpdates()
      tableView.reloadData()
  
  }
  </code></pre>