title: iOS app crashes when resuming from background
body: <p>I'm working on native iOS app using <code>UICollectionView</code> with custom <code>UICollectionViewLayout</code>. App crashes when resuming after in <code>background</code> for a period of time and I got crash logs:</p>
  
  <pre><code>    Thread 0 name:  Dispatch queue: com.apple.main-thread
      Thread 0 Crashed:
      0   libswiftCore.dylib      0x00000001005425dc 0x100404000 + 1304028
      1   MyAppName               0x000000010015e148 0x1000f4000 + 434504
      2   MyAppName               0x0000000100178284 0x1000f4000 + 541316
      3   MyAppName               0x00000001001172e0 0x1000f4000 + 144096
      4   MyAppName               0x0000000100158ef8 0x1000f4000 + 413432
      5   MyAppName               0x000000010011e5bc 0x1000f4000 + 173500
      6   UIKit                   0x000000018820b5b4 +[UIView(Animation) performWithoutAnimation:] + 80
      7   MyAppName               0x00000001001556dc 0x1000f4000 + 399068
      8   MyAppName               0x00000001001558ec 0x1000f4000 + 399596
      9   UIKit                   0x0000000188a3f3a8 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:] + 432
      10  UIKit                   0x0000000188261adc -[UICollectionView _updateVisibleCellsNow:] + 4628
      11  UIKit                   0x000000018825c808 -[UICollectionView layoutSubviews] + 228
      12  UIKit                   0x00000001881f81e4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 656
      13  QuartzCore              0x0000000185b8a994 -[CALayer layoutSublayers] + 148
      14  QuartzCore              0x0000000185b855d0 CA::Layer::layout_if_needed(CA::Transaction*) + 292
      15  QuartzCore              0x0000000185b85490 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
      16  QuartzCore              0x0000000185b84ac0 CA::Context::commit_transaction(CA::Transaction*) + 252
      17  QuartzCore              0x0000000185b84820 CA::Transaction::commit() + 500
      18  QuartzCore              0x0000000185bd8190 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 592
      19  IOKit                   0x0000000183315e54 IODispatchCalloutFromCFMessage + 372
      20  CoreFoundation          0x000000018303d030 __CFMachPortPerform + 180
      21  CoreFoundation          0x00000001830557d4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
      22  CoreFoundation          0x0000000183054f0c __CFRunLoopDoSource1 + 436
      23  CoreFoundation          0x0000000183052c64 __CFRunLoopRun + 1800
      24  CoreFoundation          0x0000000182f7cc50 CFRunLoopRunSpecific + 384
      25  GraphicsServices        0x0000000184864088 GSEventRunModal + 180
      26  UIKit                   0x0000000188266088 UIApplicationMain + 204
      27  MyAppName               0x0000000100129f5c 0x1000f4000 + 221020
      28  libdyld.dylib           0x0000000182b1a8b8 start + 4
  </code></pre>
  
  <p>How to solve or debug this problem?</p>
  
  <p>This is how to initialize UICollectionView and register Cell:</p>
  
  <pre><code>    collectionView = {
          let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
          collectionView.dataSource = self
          collectionView.delegate = self
          collectionView.showsVerticalScrollIndicator = false
          collectionView.showsHorizontalScrollIndicator = false
          collectionView.registerClass(MyCollectionCell.self, forCellWithReuseIdentifier: MyCollectionCell.reuse)
          collectionView.registerClass(MyCollectionHeaderCell.self, forSupplementaryViewOfKind: MyCollectionHeaderCell.kind, withReuseIdentifier: MyCollectionHeaderCell.reuse)
          return collectionView
          }()
  </code></pre>