0

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

Crash Info

You can find the sample project here

Kirty07
  • 53
  • 4

1 Answers1

-1

1. Please try to find out what is the type of self.lblContainer.isUserInteractionEnabled (I'm sure that it's a Boolean) by doing print(type(of:self.lblContainer.isUserInteractionEnabled))

2. Look at this other stack overflow post, here, to find the error that appears

aemon4
  • 1,037
  • 6
  • 11