title: Custom tableview(cell) with checkmark
body: <p>I want to do an app like a to-do app with a  tableview. When I hit the add button (system provided by <code>self.navigationItem.rightBarButtonItem = addButton</code>) a new tableview appears and a list with given items (provided by an entity of coreData).
  Now I want to set by a touch in a cell a checkmark and at the end I want to press the "save" button. For taking all selected (checked items) in the first tableview.</p>
  
  <p>I thought  to do it in <code>didSelectRowAtIndexPath</code>.
  But when I scroll up and down I get checkmarks even in cells that I didn t checked. then I tried the following code:</p>
  
  <p>in<code>cellForRowAtIndexPath</code></p>
  
  <pre><code>cell.detailObejct = (dataOfEntity[indexPath.row])
  if checked[indexPath.row] == false {
  
      cell.accessoryType = .None
  }
  else if checked[indexPath.row] == true {
  
      cell.accessoryType = .Checkmark
  }
  </code></pre>
  
  <p>and in </p>
  
  <pre><code>override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
      if let cell = tableView.cellForRowAtIndexPath(indexPath) {
          if cell.accessoryType == .Checkmark
          {
              cell.accessoryType = .None
              checked[indexPath.row] = false
          }
          else
          {
              cell.accessoryType = .Checkmark
              checked[indexPath.row] = true
          }
  }
  </code></pre>
  
  <p>but when I run that code I get an error that says array index out of range. The array is declared as </p>
  
  <pre><code>var checked = [Bool]()
  </code></pre>