title: iOS IBOutlet is non-nil, somehow being scavenged to nil
body: <p>TL;DR: I have an <code>IBOutlet</code> (<code>UILabel</code>) that is properly connected in Storyboard. Accessing (unwrapping) it works fine in <code>viewDidLoad()</code> ... but a few seconds later its value is nil. A watchpoint says that the outlet changes right after a call to <code>viewDidLayoutSubviews()</code>, <em>but...</em> a <code>print()</code> call at the end of <code>viewDidLayoutSubviews()</code> shows it non-nil.</p>
  
  <p>This is very similar to <a href="https://stackoverflow.com/questions/41812047/iboutlet-is-nil">IBOutlet is nil</a> but his solution (track value with <code>didSet()</code>) did not work. (There are many related posts but all had trivial solutions.)</p>
  
  <p>What I have done:</p>
  
  <ul>
  <li>Reconnected the outlet to the Label — from both sides</li>
  <li>Deleted the Label and reconnected it</li>
  <li>Cleaned the project</li>
  <li>Deleted the DerivedData </li>
  <li>Quit and restarted Xcode</li>
  <li>Quit and restarted my Mac</li>
  <li>Added a <code>didSet()</code> method to the outlet.
  
  <ul>
  <li>It triggers during <code>viewDidLoad()</code> and shows a non-nil value.</li>
  <li>In <code>viewDidLoad()</code> I set its text value with no problem</li>
  <li>It does <em>not</em> trigger before the nil-unwrapping crash</li>
  </ul></li>
  <li>Added a watchpoint to the variable. 
  
  <ul>
  <li>This <em>does</em> trigger before crash (right after <code>viewDidLayoutSubviews()</code> and shows the following:</li>
  </ul></li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/Nphl4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nphl4.jpg" alt="screenshot of Xcode debugger"></a></p>
  
  <p>As mentioned before, at exit of the most recent method call before the watchpoint (<code>viewDidLayoutSubviews()</code>) the outlet is non-nil.</p>
  
  <p>These crashes seem always to involve subviews of a particular superview. I added a watchpoint to the superview's outlet but it never triggers.</p>
  
  <p>What could be inciting my code to let go of this weak reference?</p>