From c904582015d5a8eed917d79a7f28ea2b5a8ddde3 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sun, 28 Apr 2019 20:57:54 +1200 Subject: [PATCH] Fix layout constraint comparison --- Source/LayoutConstraint.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/LayoutConstraint.swift b/Source/LayoutConstraint.swift index 8bb5ed2..9abb45f 100644 --- a/Source/LayoutConstraint.swift +++ b/Source/LayoutConstraint.swift @@ -44,9 +44,21 @@ public class LayoutConstraint : NSLayoutConstraint { } internal func ==(lhs: LayoutConstraint, rhs: LayoutConstraint) -> Bool { - guard lhs.firstItem === rhs.firstItem && - lhs.secondItem === rhs.secondItem && - lhs.firstAttribute == rhs.firstAttribute && + // ensure first anchor items match + guard let item1 = lhs.firstAnchor.item, + let item2 = rhs.firstAnchor.item, + item1 === item2 else { + return false + } + + // ensure second anchor items match + guard ((lhs.secondAnchor?.item == nil && rhs.secondAnchor?.item == nil) || + (lhs.secondAnchor?.item === rhs.secondAnchor?.item)) else { + return false + } + + // ensure attributes, relation, priorty and multiplier match + guard lhs.firstAttribute == rhs.firstAttribute && lhs.secondAttribute == rhs.secondAttribute && lhs.relation == rhs.relation && lhs.priority == rhs.priority &&