简体   繁体   English

由于在 11.3 以上 Xcode 版本中使用局部 var 变量进行优化,iOS App Crash

[英]iOS App Crash due to optimisation in Xcode version above 11.3 using local var variables

I am generating a build with optimization using XCode 11.6.我正在使用 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.只是想知道为什么我只因使用高于 11.3 的 XCode 版本生成的优化构建而崩溃。

    //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您可以在此处找到示例项目

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)) 1.请尝试通过执行print(type(of:self.lblContainer.isUserInteractionEnabled))找出self.lblContainer.isUserInteractionEnabled的类型(我确定它是布尔值print(type(of:self.lblContainer.isUserInteractionEnabled))

2. Look at this other stack overflow post, here , to find the error that appears 2.看这个其他堆栈溢出帖子, here ,找到出现的错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM