Sort of an odd problem. I have an app and a framework. Both projects are about 95% swift. ( some exceptions like sqlite config which wanted var args in c ... Swift did not like that ) In debug mode, the program runs as expected. Things are moving along positively and I decided it was time to try some optimizations out. eg. Make classes final and turn on whole module optimization -- optimize across files is my understanding.
If I turn on whole module optimization on both the app and the framework, then the app crashes. An unexpected nil in a optional. If I only turn on whole module optimization on the frame work but leave the app fast optimization or debug, then the app does not crash.
After some more investigation, it appears a class that inherits NSObject and overrides the initialize method was not called. Turns out the particular class only has class methods and initializes a static properties once. That is no instance methods. ( though it inherits instance methods from NSObject but I'm not using those instance methods ) But if whole module optimization is on for the framework and the app, then initialize never gets called.
For kicks, I got rid of the NSObject inheritance. Then I attempted to set a static property with a cloture. The cloture would return a bool but also setup too. But that never got called either -- it could not set up its singleton state. So, the app crashed. Data structures not constructed resulting in a nil in an optional.
Oddly, what did work was to create an instance of the class and throw it away. I'm not using instance methods here. In this case, the overridden initialize method in NSObject was called once. So, the bug is I should not have to create an instance. Should it be that if the class method is called, then initialize must be called the first time automatically? Whole module optimization seems to interfere with this and debug mode works. Inconsistent behavior...