From 1754aed4dcfeda4e16b700e7b8095c73169c7cec Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Mon, 5 Aug 2019 18:16:37 +1200 Subject: [PATCH] Revert #574 --- Source/LayoutConstraint.swift | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/Source/LayoutConstraint.swift b/Source/LayoutConstraint.swift index bf8ef3f..5425ea8 100644 --- a/Source/LayoutConstraint.swift +++ b/Source/LayoutConstraint.swift @@ -44,36 +44,17 @@ public class LayoutConstraint : NSLayoutConstraint { } internal func ==(lhs: LayoutConstraint, rhs: LayoutConstraint) -> Bool { - #if os(OSX) - // 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 - } - #else - guard lhs.firstAnchor == rhs.firstAnchor else { - return false - } - guard ((lhs.secondAnchor == nil && rhs.secondAnchor == nil) || - (lhs.secondAnchor! == rhs.secondAnchor!)) else { - return false - } - #endif - - - // ensure attributes, relation, priorty and multiplier match + // If firstItem or secondItem on either constraint has a dangling pointer + // this comparison can cause a crash. The solution for this is to ensure + // your layout code hold strong references to things like Views, LayoutGuides + // and LayoutAnchors as SnapKit will not keep strong references to any of these. guard lhs.firstAttribute == rhs.firstAttribute && lhs.secondAttribute == rhs.secondAttribute && lhs.relation == rhs.relation && lhs.priority == rhs.priority && - lhs.multiplier == rhs.multiplier else { + lhs.multiplier == rhs.multiplier && + lhs.secondItem === rhs.secondItem && + lhs.firstItem === rhs.firstItem else { return false } return true