This commit is contained in:
Robert Payne 2019-08-05 18:16:37 +12:00
parent 222e14ab37
commit 1754aed4dc
1 changed files with 7 additions and 26 deletions

View File

@ -44,36 +44,17 @@ public class LayoutConstraint : NSLayoutConstraint {
} }
internal func ==(lhs: LayoutConstraint, rhs: LayoutConstraint) -> Bool { internal func ==(lhs: LayoutConstraint, rhs: LayoutConstraint) -> Bool {
#if os(OSX) // If firstItem or secondItem on either constraint has a dangling pointer
// ensure first anchor items match // this comparison can cause a crash. The solution for this is to ensure
guard let item1 = lhs.firstAnchor.item, // your layout code hold strong references to things like Views, LayoutGuides
let item2 = rhs.firstAnchor.item, // and LayoutAnchors as SnapKit will not keep strong references to any of these.
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
guard lhs.firstAttribute == rhs.firstAttribute && guard lhs.firstAttribute == rhs.firstAttribute &&
lhs.secondAttribute == rhs.secondAttribute && lhs.secondAttribute == rhs.secondAttribute &&
lhs.relation == rhs.relation && lhs.relation == rhs.relation &&
lhs.priority == rhs.priority && 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 false
} }
return true return true