I am generating a build with optimization using XCode 11.6.
The optimization build settings are
Apple CLang Code Generation
Optimization Level: Fastest, Smallest [-Os]
Swift Compiler - Code Generation
Optimization Level: Optimize for speed [-O]
I am getting a crash for the below piece of code. Just wanted to know why I am getting a crash only for optimized build generated with XCode version above 11.3.
//it crashes only when the object is declared as var not let
var view : UIView = UIView.init(frame: CGRect.zero)
//lblContainer is a weak variable defined in class
self.lblContainer = view;
//it always crashes here
self.lblContainer.isUserInteractionEnabled = false
self.lblContainer.translatesAutoresizingMaskIntoConstraints = false;
self.addSubview(self.lblContainer)
self.lblContainer.backgroundColor = UIColor.clear;
self.lblContainer.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true;
self.lblContainer.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true;
self.lblContainer.leftAnchor.constraint(greaterThanOrEqualTo: self.leftAnchor, constant: 8.0).isActive = true
self.lblContainer.rightAnchor.constraint(lessThanOrEqualTo: self.rightAnchor, constant: -8.0).isActive = true
You can find the sample project here