我正在使用XCode 11.6生成一个带有优化的构建。
优化构建设置为
Apple CLang Code Generation
Optimization Level: Fastest, Smallest [-Os]
Swift Compiler - Code Generation
Optimization Level: Optimize for speed [-O]我在下面的代码中遇到了崩溃。我只想知道为什么只有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

您可以在此处找到sample project
发布于 2020-11-19 18:18:37
1.请尝试通过执行print(type(of:self.lblContainer.isUserInteractionEnabled))找出self.lblContainer.isUserInteractionEnabled的类型(我确定它是布尔值)
2.查看另一个堆栈溢出post here,以查找出现的错误
https://stackoverflow.com/questions/64908366
复制相似问题