From 180ff1477e999d009f15488f3824c22bd4ce15fa Mon Sep 17 00:00:00 2001 From: Txai Wieser Date: Fri, 30 Sep 2016 01:57:23 -0300 Subject: [PATCH] Add ConstraintMaker shortcuts for superview access (#341) Added two new shortcuts for access superview in ConstraintMakerRelatable `greaterThanOrEqualToSuperview` `lessThanOrEqualToSuperview` --- Source/ConstraintMakerRelatable.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Source/ConstraintMakerRelatable.swift b/Source/ConstraintMakerRelatable.swift index 40a46fa..d50b423 100644 --- a/Source/ConstraintMakerRelatable.swift +++ b/Source/ConstraintMakerRelatable.swift @@ -87,9 +87,24 @@ public class ConstraintMakerRelatable { return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line) } + @discardableResult + public func lessThanOrEqualToSuperview(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { + guard let other = self.description.view.superview else { + fatalError("Expected superview but found nil when attempting make constraint `lessThanOrEqualToSuperview`.") + } + return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line) + } + @discardableResult public func greaterThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable { return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line) } + @discardableResult + public func greaterThanOrEqualToSuperview(_ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable { + guard let other = self.description.view.superview else { + fatalError("Expected superview but found nil when attempting make constraint `greaterThanOrEqualToSuperview`.") + } + return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line) + } }