【发布时间】:2021-02-18 20:15:49
【问题描述】:
如何调试这个错误?似乎没有额外的错误描述。
失败的代码:
import UIKit
import PlaygroundSupport
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
containerView.backgroundColor = UIColor.white
let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(stackView)
stackView.addConstraint(.init(item: stackView, attribute: .top, relatedBy: .equal, toItem: containerView, attribute: .top, multiplier: 1, constant: 0))
stackView.addConstraint(.init(item: stackView, attribute: .leading, relatedBy: .equal, toItem: containerView, attribute: .leading, multiplier: 1, constant: 0))
PlaygroundPage.current.liveView = containerView // error: Execution was interrupted, reason: signal SIGABRT.
完全错误:
错误:执行被中断,原因:信号 SIGABRT。过程 一直留在中断的地方,使用“线程 return -x" 返回表达式求值前的状态。
完整的控制台日志:
libc++abi.dylib:以 NSException 类型的未捕获异常终止
【问题讨论】:
-
我认为那是因为您在视图实际位于层次结构之前添加了约束
-
@aheze 我试图在 containerView 初始化后立即移动 liveView 分配行,但现在在添加约束时出现相同的错误
标签: ios swift swift-playground