Edit: The HOW is not important, I'm interested in the WHY. Here is a scenario that triggers the WHAT:
I am loading a simply boolean value from UserDefaults.standard in my ViewController's viewWillAppear method. I do not alter or delete the data, I simply load it into a variable. e.g.:
var aBool:Bool? = UserDefaults.standard.bool(forKey: "MyBoolKey")
In the VC lifecycle, viewWillAppear and viewDidAppear a guaranteed to be called once, but might be called multiple times.
In my case with this particular view controller, they are called 3 times in rapid succession. For whatever reason, on the first time these functions are called, the bool (aBool) is set and loaded from UserDefaults properly. But the 2nd and 3rd time these functions are called, UserDefaults is returning nil, and in fact no other variables stored in UserDefaults are accessible, they all return nil if you inspect them from lldb when stopping the code on the 2nd and 3rd executions.
Why is UserDefaults working on the 1st iteration, but not the 2nd or 3rd?