我已经升级到swift 2,这个功能给我带来了麻烦。
这在尝试运行应用时导致错误。我不知道如何修复此问题,因为我正在尝试将其升级到swift 2.我已经进行了大量搜索,但无法修复代码。创建函数时,错误发生在:NSLayoutFormatOptions = nil
。
internal extension UIView {
func addConstraints(format format: String, options: NSLayoutFormatOptions = nil, metrics: [String: AnyObject]? = nil, views: [String: UIView]) {
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(format, options: options, metrics: metrics, views: views))
}
func addUniversalConstraints(format format: String, options: NSLayoutFormatOptions = nil, metrics: [String: AnyObject]? = nil, views: [String: UIView]) {
addConstraints(format: "H:\(format)", options: options, metrics: metrics, views: views)
addConstraints(format: "V:\(format)", options: options, metrics: metrics, views: views)
}
}
谢谢你能提供帮助。 :)
您诚挚的 Gerard Grundy
答案 0 :(得分:15)
您的options
参数未声明为可选,因此您无法设置默认值nil
。
使options
成为可选:
func addConstraints(format format: String, options: NSLayoutFormatOptions? = nil, metrics: [String: AnyObject]? = nil, views: [String: UIView])
或从签名中删除= nil
:
func addConstraints(format format: String, options: NSLayoutFormatOptions, metrics: [String: AnyObject]? = nil, views: [String: UIView])