From 3f529652a4cfa463b7b4bc5cee06c5f9ac9d0887 Mon Sep 17 00:00:00 2001 From: vhosune Date: Fri, 23 Sep 2016 12:54:49 +0200 Subject: [PATCH] =?UTF-8?q?fix=20"Mutating=20a=20priority=20from=20require?= =?UTF-8?q?d=20to=20not=20on=20an=20installed=20constra=E2=80=A6=20(#323)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix "Mutating a priority from required to not on an installed constraint (or vice-versa) is not supported." when the priority is not changed * add more check when changing layout constraint priority * add more lenient check when changing layout constraint priority * fix UILayoutPriorityRequired available only on iOS * fix undeclared UILayoutPriority on macOS * add check for tvOS --- Source/Constraint.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index b93a8d9..7324c59 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -228,7 +228,17 @@ public class Constraint { for layoutConstraint in self.layoutConstraints { let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute) - layoutConstraint.priority = self.priority.constraintPriorityTargetValue + + #if os(iOS) || os(tvOS) + let requiredPriority: UILayoutPriority = UILayoutPriorityRequired + #else + let requiredPriority: Float = 1000.0 + #endif + + + if (layoutConstraint.priority < requiredPriority), (self.priority.constraintPriorityTargetValue != requiredPriority) { + layoutConstraint.priority = self.priority.constraintPriorityTargetValue + } } }