From 16090bde5d599952cfa540919937669421ebd202 Mon Sep 17 00:00:00 2001 From: Akiva Leffert Date: Wed, 23 Sep 2015 13:43:29 -0400 Subject: [PATCH] Add support for the iOS 9 Layout Anchor API. --- Source/ConstraintDescription.swift | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Source/ConstraintDescription.swift b/Source/ConstraintDescription.swift index d401192..1387c8e 100644 --- a/Source/ConstraintDescription.swift +++ b/Source/ConstraintDescription.swift @@ -95,6 +95,8 @@ public protocol ConstraintDescriptionRelatable: class { func equalTo(other: View) -> ConstraintDescriptionEditable @available(iOS 7.0, *) func equalTo(other: LayoutSupport) -> ConstraintDescriptionEditable + @available(iOS 9.0, *) + func equalTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable func equalTo(other: Float) -> ConstraintDescriptionEditable func equalTo(other: Double) -> ConstraintDescriptionEditable func equalTo(other: CGFloat) -> ConstraintDescriptionEditable @@ -108,6 +110,8 @@ public protocol ConstraintDescriptionRelatable: class { func lessThanOrEqualTo(other: View) -> ConstraintDescriptionEditable @available(iOS 7.0, *) func lessThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable + @available(iOS 9.0, *) + func lessThanOrEqualTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable func lessThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable func lessThanOrEqualTo(other: Double) -> ConstraintDescriptionEditable func lessThanOrEqualTo(other: CGFloat) -> ConstraintDescriptionEditable @@ -121,6 +125,8 @@ public protocol ConstraintDescriptionRelatable: class { func greaterThanOrEqualTo(other: View) -> ConstraintDescriptionEditable @available(iOS 7.0, *) func greaterThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable + @available(iOS 9.0, *) + func greaterThanOrEqualTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable func greaterThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable func greaterThanOrEqualTo(other: Double) -> ConstraintDescriptionEditable func greaterThanOrEqualTo(other: CGFloat) -> ConstraintDescriptionEditable @@ -224,6 +230,10 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain internal func equalTo(other: LayoutSupport) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .Equal) } + @available(iOS 9.0, *) + internal func equalTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable { + return self.constrainTo(other, relation: .Equal) + } internal func equalTo(other: Float) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .Equal) } @@ -261,6 +271,10 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain internal func lessThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .LessThanOrEqualTo) } + @available(iOS 9.0, *) + internal func lessThanOrEqualTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable { + return self.constrainTo(other, relation: .LessThanOrEqualTo) + } internal func lessThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .LessThanOrEqualTo) } @@ -298,6 +312,10 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain internal func greaterThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .GreaterThanOrEqualTo) } + @available(iOS 9.0, *) + internal func greaterThanOrEqualTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable { + return self.constrainTo(other, relation: .LessThanOrEqualTo) + } internal func greaterThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .GreaterThanOrEqualTo) } @@ -547,6 +565,11 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation) } + @available(iOS 9.0, *) + private func constrainTo(other: NSLayoutAnchor, relation: ConstraintRelation) -> ConstraintDescription { + return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation) + } + private func constrainTo(other: Float, relation: ConstraintRelation) -> ConstraintDescription { self.constant = other return constrainTo(ConstraintItem(object: nil, attributes: ConstraintAttributes.None), relation: relation) @@ -571,4 +594,4 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain self.constant = other return constrainTo(ConstraintItem(object: nil, attributes: ConstraintAttributes.None), relation: relation) } -} \ No newline at end of file +}