如何将多个constraintsWithVisualFormat:options:metrics:views:
调用返回的布局约束收集到一个数组中?例如,Swift编译器将此标记为错误[NSLayoutConstraint] is not identical to 'UInt8'
:
var newConstraints: [NSLayoutConstraint] = []
newConstraints += NSLayoutConstraint.constraintsWithVisualFormat(format1, options: nil, metrics: nil, views: views)
我正在使用Xcode 6.1。
答案 0 :(得分:1)
constraintsWithVisualFormat
返回[AnyObject]
。您需要将其[NSLayoutConstraint]
强制转换为[NSLayoutConstraint]
类型的数组:
newConstraints += NSLayoutConstraint.constraintsWithVisualFormat(format1, options: nil, metrics: nil, views: views)
as [NSLayoutConstraint]