# Crash when i try to add a to-do

**URL:** <https://forums.kodeco.com/t/crash-when-i-try-to-add-a-to-do/16948>\
**Category:** iOS Apprentice\
**Created:** [July 5, 2016, 9:15am UTC](https://forums.kodeco.com/t/crash-when-i-try-to-add-a-to-do/16948 "2016-07-05T09:15:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dom](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/dom/32/79544_2.png) [@dom](https://forums.kodeco.com/u/dom)\
**Post date:** [July 5, 2016, 9:15am UTC](https://forums.kodeco.com/t/crash-when-i-try-to-add-a-to-do/16948/1 "2016-07-05T09:15:34Z")

</div>

reason: ‘attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update’

`func itemDetailViewController(controller: ItemDetailViewController, didFinishAddItem item: ChecklistItem) {  
let newRowIndex = checklist.items.count

```
    items.append(item)
    
    let indexPath = NSIndexPath(forRow: newRowIndex, inSection: 0)//crash in this line 
    let indexPaths = [indexPath]
    tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: .Automatic)
    
    dismissViewControllerAnimated(true, completion: nil)
}`

```

---

<div class="post-metadata">

**Author:** ![rcasey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcasey/32/82229_2.png) [@rcasey](https://forums.kodeco.com/u/rcasey)\
**Post date:** [July 13, 2016, 7:07am UTC](https://forums.kodeco.com/t/crash-when-i-try-to-add-a-to-do/16948/2 "2016-07-13T07:07:10Z")

</div>

Double-check your code.  
You reference **checklist.items** for your count, but reference **items** when you append your new item.

---

<div class="post-metadata">

**Author:** ![dom](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/dom/32/79544_2.png) [@dom](https://forums.kodeco.com/u/dom)\
**Post date:** [July 13, 2016, 3:56pm UTC](https://forums.kodeco.com/t/crash-when-i-try-to-add-a-to-do/16948/3 "2016-07-13T15:56:53Z")

</div>

yeah , Thanks . I found it
