Skip to content

Commit c904582

Browse files
committed
Fix layout constraint comparison
1 parent 5b0282c commit c904582

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Source/LayoutConstraint.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,21 @@ public class LayoutConstraint : NSLayoutConstraint {
4444
}
4545

4646
internal func ==(lhs: LayoutConstraint, rhs: LayoutConstraint) -> Bool {
47-
guard lhs.firstItem === rhs.firstItem &&
48-
lhs.secondItem === rhs.secondItem &&
49-
lhs.firstAttribute == rhs.firstAttribute &&
47+
// ensure first anchor items match
48+
guard let item1 = lhs.firstAnchor.item,
49+
let item2 = rhs.firstAnchor.item,
50+
item1 === item2 else {
51+
return false
52+
}
53+
54+
// ensure second anchor items match
55+
guard ((lhs.secondAnchor?.item == nil && rhs.secondAnchor?.item == nil) ||
56+
(lhs.secondAnchor?.item === rhs.secondAnchor?.item)) else {
57+
return false
58+
}
59+
60+
// ensure attributes, relation, priorty and multiplier match
61+
guard lhs.firstAttribute == rhs.firstAttribute &&
5062
lhs.secondAttribute == rhs.secondAttribute &&
5163
lhs.relation == rhs.relation &&
5264
lhs.priority == rhs.priority &&

0 commit comments

Comments
 (0)