From ddf15594fdd565a5909127a9d88e300342cc3e8f Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 23 Nov 2016 15:28:35 +1300 Subject: [PATCH] Improve looping of existing constraints --- Source/Constraint.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index c4df105..3c2c242 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -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)") }