【问题标题】:swift 3 error [_SwiftValue nsli_superitem]快速 3 错误 [_SwiftValue nsli_superitem]
【发布时间】:2017-01-30 02:01:27
【问题描述】:

在 swift 3 转换后,我收到了这个错误。

'NSInvalidArgumentException',原因:'-[_SwiftValue nsli_superitem]:无法识别的选择器发送到实例 0x600000a54820'

有问题的代码是这样的,它可以在 swift 2 中正常工作:

let views = ["newView": userLabel]
let widthConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:[newView(0)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
userMainLabel.addConstraints(widthConstraints)

【问题讨论】:

    标签: ios swift swift3 ios10 xcode8


    【解决方案1】:

    这是 swift 3 的问题,其中字典被视为 [String: UIView?]

    解决方法是将类型指定为非可选

    let views: [String: UIView] = ["newView": userLabel]
    

    【讨论】:

    • 在我的例子中,我的视图被声明为可选的,但似乎在 Swift 2 中编译器隐含地解开了它。我喜欢这个。更可预测。小心字典中的选项!呵呵
    • 谢谢。我浪费了一天才弄明白:(
    猜你喜欢
    • 1970-01-01
    • 2017-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多