Explorar o código

Fix layout constraint comparison

Robert Payne %!s(int64=6) %!d(string=hai) anos
pai
achega
c904582015
Modificáronse 1 ficheiros con 15 adicións e 3 borrados
  1. 15 3
      Source/LayoutConstraint.swift

+ 15 - 3
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 &&