title: [iOS 13]: Fatal Exception: NSInvalidArgumentException Can't add self as subview ([NSCache init])
body: <p>I've seen similar issues/questions on Stack Overflow, but they didn't help.</p>
  
  <p>I built the app with Xcode 11 and iOS 13 SDK. The problem is that I get all these crashes only on iOS 13+, even though my app supports iOS 10+ and there are ~50% iOS 12 users among all. Also, I cannot debug or reproduce it.</p>
  
  <p><strong>From this info I inferred the issue must be specific to iOS 13. Has anyone come across the same issue recently? Possible causes, solutions?</strong></p>
  
  <p>Here is the stack trace from Crashlytics:</p>
  
  <pre><code>Fatal Exception: NSInvalidArgumentException
  0  CoreFoundation                 0x1c25e1c30 __exceptionPreprocess
  1  libobjc.A.dylib                0x1c22fc0c8 objc_exception_throw
  2  CoreFoundation                 0x1c24d13ac -[NSCache init]
  3  UIKitCore                      0x1c6b189a8 -[UIView(Internal) _addSubview:positioned:relativeTo:]
  4  UIKitCore                      0x1c6078bb4 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke_2
  5  UIKitCore                      0x1c6b11f60 +[UIView(Animation) performWithoutAnimation:]
  6  UIKitCore                      0x1c6078630 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke
  7  UIKitCore                      0x1c6b1784c +[UIView(Internal) _performBlockDelayingTriggeringResponderEvents:forScene:]
  8  UIKitCore                      0x1c6078088 -[_UINavigationParallaxTransition animateTransition:]
  9  UIKitCore                      0x1c606e2b0 ___UIViewControllerTransitioningRunCustomTransition_block_invoke_2
  10 UIKitCore                      0x1c61822f8 +[UIInputResponderController _pinInputViewsForInputResponderController:onBehalfOfResponder:duringBlock:]
  11 UIKitCore                      0x1c606e238 ___UIViewControllerTransitioningRunCustomTransition_block_invoke.648
  12 UIKitCore                      0x1c6b11c0c +[UIView(Animation) _setAlongsideAnimations:toRunByEndOfBlock:]
  13 UIKitCore                      0x1c606e088 _UIViewControllerTransitioningRunCustomTransition
  14 UIKitCore                      0x1c5f9d77c -[UINavigationController _startCustomTransition:]
  15 UIKitCore                      0x1c5fb0c18 -[UINavigationController _startDeferredTransitionIfNeeded:]
  16 UIKitCore                      0x1c5fb20f8 -[UINavigationController __viewWillLayoutSubviews]
  17 UIKitCore                      0x1c5f954e0 -[UILayoutContainerView layoutSubviews]
  18 UIKitCore                      0x1c6b1fabc -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
  19 libobjc.A.dylib                0x1c22f7af0 -[NSObject performSelector:withObject:]
  20 QuartzCore                     0x1c90be0f4 -[CALayer layoutSublayers]
  21 QuartzCore                     0x1c90be3fc CA::Layer::layout_if_needed(CA::Transaction*)
  22 QuartzCore                     0x1c90d1964 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
  23 QuartzCore                     0x1c9016c1c CA::Context::commit_transaction(CA::Transaction*, double)
  24 QuartzCore                     0x1c9041bd8 CA::Transaction::commit()
  25 QuartzCore                     0x1c90427ac CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
  26 CoreFoundation                 0x1c255c67c __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
  27 CoreFoundation                 0x1c255731c __CFRunLoopDoObservers
  28 CoreFoundation                 0x1c25578cc __CFRunLoopRun
  29 CoreFoundation                 0x1c2557098 CFRunLoopRunSpecific
  30 GraphicsServices               0x1cc6c1534 GSEventRunModal
  31 UIKitCore                      0x1c66777ac UIApplicationMain
  </code></pre>
  
  <p><strong>Update 1</strong>: The issue is relevant to all iPhones running iOS 13, not only iPhone X(S,R) line.</p>
  
  <p><strong>Update 2</strong>: The issue is relevant to iOS 12 as well, but crashes happen rarely in comparison to iOS 13. My guess is that the issue is related to building the project with iOS 13 SDK, because the same code built with iOS 12 SDK didn't emit such crashes and the navigation logic wasn't updated.</p>