title: Swift 2: UITableView 'reloadSections' method crash in iOS 9
body: <p>My app was working fine prior to the forced upgrade to Swift 2.x.  My code below is executed on an IBAction for a button that "collapses" the cell, e.g. it replaces it with another layout and then attempts to reload the cell, which for various reasons I've been forced to include each cell in its own section (so, extensibly I'm reloading the section).  I've tried outputting various variables to the terminal; the inputs are sound.  I've also tried wrapping this in .beginUpdates() and .endUpdates() and when walking through this in the debugger, it will just throw the below exception on the .endUpdates() call instead of the .reloadSections() call.  I have also tried replacing .reloadSections() with a blanket call to .reloadData() and I receive the same stack trace, making me believe it's internal to the TableView object somehow.</p>
  
  <pre><code>// Set Selected Patient Configuration to "Collapsed"
  patientList.patients[ sender.tag ].updateConfiguration( collapsedConfiguration )
  let animation = UITableViewRowAnimation.Automatic
  
  // Retrieve Current Table View and Animate Changes
  let tableView = self.superview!.superview as! UITableView
  
  // Reload Section with Animation
  tableView.reloadSections(NSIndexSet( index: sender.tag ), withRowAnimation: animation )
  </code></pre>
  
  <p>My code will evaluate the backing data's collapsed state and draw it in either the full or collapsed view.</p>
  
  <pre><code>*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 2 beyond bounds [0 .. 0]'
  *** First throw call stack:
  (
      0   CoreFoundation                      0x00e2fa84 __exceptionPreprocess + 180
      1   libobjc.A.dylib                     0x03235e02 objc_exception_throw + 50
      2   CoreFoundation                      0x00cdd211 -[__NSArrayM insertObject:atIndex:] + 881
      3   Foundation                          0x01510134 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 115
      4   CoreFoundation                      0x00d38630 -[NSMutableArray insertObjects:count:atIndex:] + 192
      5   CoreFoundation                      0x00d38322 -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 322
      6   CoreFoundation                      0x00d381c2 -[NSMutableArray addObjectsFromArray:] + 834
      7   UIKit                               0x024f4d4f -[UIRuntimeOutletCollectionConnection performConnect] + 964
      8   UIKit                               0x024f4daf -[UIRuntimeOutletCollectionConnection connect] + 33
      9   libobjc.A.dylib                     0x0324a00c -[NSObject performSelector:] + 62
      10  CoreFoundation                      0x00d60571 -[NSArray makeObjectsPerformSelector:] + 273
      11  UIKit                               0x021b06f6 -[UINib instantiateWithOwner:options:] + 2102
      12  UIKit                               0x01eeed6c -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 457
      13  UIKit                               0x01eef173 -[UITableView dequeueReusableCellWithIdentifier:] + 48
      14  Halo                                0x001b5174 _TFC4Halo18MainViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 2356
      15  Halo                                0x001be459 _TToFC4Halo18MainViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 89
      16  UIKit                               0x01f03a19 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
      17  UIKit                               0x01f03b47 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 90
      18  UIKit                               0x022568cc -[_UITableViewUpdateSupport(Private) _setupAnimationsForNewlyInsertedCells] + 8353
      19  UIKit                               0x0226181a -[_UITableViewUpdateSupport _setupAnimations] + 161
      20  UIKit                               0x01ed7fd3 -[UITableView _updateWithItems:updateSupport:] + 3653
      21  UIKit                               0x01ecfc91 -[UITableView _endCellAnimationsWithContext:] + 17491
      22  UIKit                               0x01eea538 -[UITableView _updateSections:updateAction:withRowAnimation:headerFooterOnly:] + 460
      23  UIKit                               0x01eea625 -[UITableView reloadSections:withRowAnimation:] + 73
      24  Halo                                0x00105e10 _TFC4Halo28FullPatientViewTableViewCell19collapseButtonPressfS0_FCSo8UIButtonT_ + 6208
      25  Halo                                0x0010645d _TToFC4Halo28FullPatientViewTableViewCell19collapseButtonPressfS0_FCSo8UIButtonT_ + 61
      26  libobjc.A.dylib                     0x0324a0b5 -[NSObject performSelector:withObject:withObject:] + 84
      27  UIKit                               0x01d8016a -[UIApplication sendAction:to:from:forEvent:] + 118
      28  UIKit                               0x01d800e9 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
      29  UIKit                               0x01f1e19f -[UIControl sendAction:to:forEvent:] + 79
      30  UIKit                               0x01f1e51f -[UIControl _sendActionsForEvents:withEvent:] + 408
      31  UIKit                               0x01f1d525 -[UIControl touchesEnded:withEvent:] + 714
      32  UIKit                               0x022efeaa _UIGestureRecognizerUpdate + 12763
      33  UIKit                               0x01dfabdf -[UIWindow _sendGesturesForEvent:] + 1559
      34  UIKit                               0x01dfc298 -[UIWindow sendEvent:] + 1137
      35  UIKit                               0x01da1efb -[UIApplication sendEvent:] + 266
      36  UIKit                               0x01d77cb6 _UIApplicationHandleEventQueue + 7802
      37  CoreFoundation                      0x00d49d1f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
      38  CoreFoundation                      0x00d3f9ab __CFRunLoopDoSources0 + 523
      39  CoreFoundation                      0x00d3edc8 __CFRunLoopRun + 1032
      40  CoreFoundation                      0x00d3e706 CFRunLoopRunSpecific + 470
      41  CoreFoundation                      0x00d3e51b CFRunLoopRunInMode + 123
      42  GraphicsServices                    0x058c0664 GSEventRunModal + 192
      43  GraphicsServices                    0x058c04a1 GSEventRun + 104
      44  UIKit                               0x01d7e1eb UIApplicationMain + 160
      45  Halo                                0x0011eb6c main + 140
      46  libdyld.dylib                       0x03ceca21 start + 1
      47  ???                                 0x00000001 0x0 + 1
  )
  libc++abi.dylib: terminating with uncaught exception of type NSException
  </code></pre>
  
  <p>The stack is not very helpful to me and I can't even figure out the opening message: "insertObject:atIndex:]: index 2 beyond bounds [0 .. 0]."  No where in this sample and my test with a single table entry should there be an index of '2.'  Any help you could provide would be appreciated.</p>
  
  <p>Here's my 'bt' on this exception:</p>
  
  <pre><code>* thread #1: tid = 0xc9ca7, 0x0401969a libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
      frame #0: 0x0401969a libsystem_kernel.dylib`__pthread_kill + 10
      frame #1: 0x03fe4634 libsystem_pthread.dylib`pthread_kill + 101
      frame #2: 0x03d9339d libsystem_c.dylib`abort + 156
      frame #3: 0x04034ae7 libc++abi.dylib`abort_message + 151
      frame #4: 0x04055683 libc++abi.dylib`default_terminate_handler() + 300
      frame #5: 0x032360b6 libobjc.A.dylib`_objc_terminate() + 108
      frame #6: 0x04052d0d libc++abi.dylib`std::__terminate(void (*)()) + 14
      frame #7: 0x0405293e libc++abi.dylib`__cxa_rethrow + 103
      frame #8: 0x03235fad libobjc.A.dylib`objc_exception_rethrow + 47
      frame #9: 0x00d3e7d0 CoreFoundation`CFRunLoopRunSpecific + 672
      frame #10: 0x00d3e51b CoreFoundation`CFRunLoopRunInMode + 123
      frame #11: 0x058c0664 GraphicsServices`GSEventRunModal + 192
      frame #12: 0x058c04a1 GraphicsServices`GSEventRun + 104
      frame #13: 0x01d7e1eb UIKit`UIApplicationMain + 160
    * frame #14: 0x0011eb6c Halo`main + 140 at AppDelegate.swift:26
      frame #15: 0x03ceca21 libdyld.dylib`start + 1
  </code></pre>
  
  <p>Per request, here's the code followed by the output:</p>
  
  <pre><code>    // Retrieve Current Table View and Animate Changes
      let tableView = self.superview!.superview as! UITableView
  
      // Test Output
      print( "tableView.numberOfSections: \(tableView.numberOfSections)" )
      print( "tableView.numberOfRowsInSection( sender.tag ): \(tableView.numberOfRowsInSection( sender.tag ))" )
  
      // Reload Section with Animation
      tableView.reloadSections(NSIndexSet( index: sender.tag ), withRowAnimation: animation )
  
      tableView.numberOfSections: 1
      tableView.numberOfRowsInSection( sender.tag ): 1
  </code></pre>