Improve looping of existing constraints

This commit is contained in:
Robert Payne 2016-11-23 15:28:35 +13:00
parent cfa5e8cb5b
commit ddf15594fd
1 changed files with 6 additions and 2 deletions

View File

@ -252,11 +252,15 @@ public class Constraint {
return
}
let layoutConstraints = self.layoutConstraints
let existingLayoutConstraints = item.constraints.map({ $0.layoutConstraints }).reduce([]) { $0 + $1 }
if updatingExisting {
var existingLayoutConstraints: [LayoutConstraint] = []
for constraint in item.constraints {
existingLayoutConstraints += constraint.layoutConstraints
}
for layoutConstraint in layoutConstraints {
let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint }
let existingLayoutConstraint = existingLayoutConstraints.first { $0.canUpdate(constraint: layoutConstraint) }
guard let updateLayoutConstraint = existingLayoutConstraint else {
fatalError("Updated constraint could not find existing matching constraint to update: \(layoutConstraint)")
}