From 210bab97c74a9fc6cd638ef1e5bf352ace6c1d72 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 19 Sep 2015 12:21:42 +1200 Subject: [PATCH] Enforce availablility for iOS 8.0+ Attributes --- Source/ConstraintAttributes.swift | 14 ++++++++++++++ Source/ConstraintDescription.swift | 18 ++++++++++++++++++ Source/ConstraintMaker.swift | 11 +++++++++++ Source/View+SnapKit.swift | 11 +++++++++++ 4 files changed, 54 insertions(+) diff --git a/Source/ConstraintAttributes.swift b/Source/ConstraintAttributes.swift index 06b3dec..2af19a7 100644 --- a/Source/ConstraintAttributes.swift +++ b/Source/ConstraintAttributes.swift @@ -67,14 +67,23 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { internal static var Baseline: ConstraintAttributes { return self.init(1024) } #if os(iOS) + @available(iOS 8.0, *) internal static var FirstBaseline: ConstraintAttributes { return self.init(2048) } + @available(iOS 8.0, *) internal static var LeftMargin: ConstraintAttributes { return self.init(4096) } + @available(iOS 8.0, *) internal static var RightMargin: ConstraintAttributes { return self.init(8192) } + @available(iOS 8.0, *) internal static var TopMargin: ConstraintAttributes { return self.init(16384) } + @available(iOS 8.0, *) internal static var BottomMargin: ConstraintAttributes { return self.init(32768) } + @available(iOS 8.0, *) internal static var LeadingMargin: ConstraintAttributes { return self.init(65536) } + @available(iOS 8.0, *) internal static var TrailingMargin: ConstraintAttributes { return self.init(131072) } + @available(iOS 8.0, *) internal static var CenterXWithinMargins: ConstraintAttributes { return self.init(262144) } + @available(iOS 8.0, *) internal static var CenterYWithinMargins: ConstraintAttributes { return self.init(524288) } #endif @@ -85,7 +94,9 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { internal static var Center: ConstraintAttributes { return self.init(768) } #if os(iOS) + @available(iOS 8.0, *) internal static var Margins: ConstraintAttributes { return self.init(61440) } + @available(iOS 8.0, *) internal static var CenterWithinMargins: ConstraintAttributes { return self.init(786432) } #endif @@ -125,6 +136,9 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { attrs.append(.Baseline) } #if os(iOS) + guard #available(iOS 8.0, *) else { + fatalError("Constrant attribute unavaialble for running platform and deployment target.") + } if (self.contains(ConstraintAttributes.FirstBaseline)) { attrs.append(.FirstBaseline) } diff --git a/Source/ConstraintDescription.swift b/Source/ConstraintDescription.swift index c7a6c2d..0fdf888 100644 --- a/Source/ConstraintDescription.swift +++ b/Source/ConstraintDescription.swift @@ -153,14 +153,23 @@ public protocol ConstraintDescriptionExtendable: ConstraintDescriptionRelatable var baseline: ConstraintDescriptionExtendable { get } #if os(iOS) + @available(iOS 8.0, *) var firstBaseline: ConstraintDescriptionExtendable { get } + @available(iOS 8.0, *) var leftMargin: ConstraintDescriptionExtendable { get } + @available(iOS 8.0, *) var rightMargin: ConstraintDescriptionExtendable { get } + @available(iOS 8.0, *) var topMargin: ConstraintDescriptionExtendable { get } + @available(iOS 8.0, *) var bottomMargin: ConstraintDescriptionExtendable { get } + @available(iOS 8.0, *) var leadingMargin: ConstraintDescriptionExtendable { get } + @available(iOS 8.0, *) var trailingMargin: ConstraintDescriptionExtendable { get } + @available(iOS 8.0, *) var centerXWithinMargins: ConstraintDescriptionExtendable { get } + @available(iOS 8.0, *) var centerYWithinMargins: ConstraintDescriptionExtendable { get } #endif } @@ -183,14 +192,23 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain internal var baseline: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.Baseline) } #if os(iOS) + @available(iOS 8.0, *) internal var firstBaseline: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.FirstBaseline) } + @available(iOS 8.0, *) internal var leftMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.LeftMargin) } + @available(iOS 8.0, *) internal var rightMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.RightMargin) } + @available(iOS 8.0, *) internal var topMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.TopMargin) } + @available(iOS 8.0, *) internal var bottomMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.BottomMargin) } + @available(iOS 8.0, *) internal var leadingMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.LeadingMargin) } + @available(iOS 8.0, *) internal var trailingMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.TrailingMargin) } + @available(iOS 8.0, *) internal var centerXWithinMargins: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.CenterXWithinMargins) } + @available(iOS 8.0, *) internal var centerYWithinMargins: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.CenterYWithinMargins) } #endif diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index ff5ab52..4cd6672 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -68,30 +68,39 @@ public class ConstraintMaker { #if os(iOS) /// firse baseline position + @available(iOS 8.0, *) public var firstBaseline: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.FirstBaseline) } /// left margin + @available(iOS 8.0, *) public var leftMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.LeftMargin) } /// right margin + @available(iOS 8.0, *) public var rightMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.RightMargin) } /// top margin + @available(iOS 8.0, *) public var topMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.TopMargin) } /// bottom margin + @available(iOS 8.0, *) public var bottomMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.BottomMargin) } /// leading margin + @available(iOS 8.0, *) public var leadingMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.LeadingMargin) } /// trailing margin + @available(iOS 8.0, *) public var trailingMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.TrailingMargin) } /// centerX within margins + @available(iOS 8.0, *) public var centerXWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterXWithinMargins) } /// centerY within margins + @available(iOS 8.0, *) public var centerYWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterYWithinMargins) } #endif @@ -108,9 +117,11 @@ public class ConstraintMaker { #if os(iOS) // top + left + bottom + right margins + @available(iOS 8.0, *) public var margins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Margins) } // centerX + centerY within margins + @available(iOS 8.0, *) public var centerWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterWithinMargins) } #endif diff --git a/Source/View+SnapKit.swift b/Source/View+SnapKit.swift index d2e2a52..ac9b771 100644 --- a/Source/View+SnapKit.swift +++ b/Source/View+SnapKit.swift @@ -70,30 +70,39 @@ public extension View { #if os(iOS) /// first baseline position + @available(iOS 8.0, *) public var snp_firstBaseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.FirstBaseline) } /// left margin + @available(iOS 8.0, *) public var snp_leftMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeftMargin) } /// right margin + @available(iOS 8.0, *) public var snp_rightMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.RightMargin) } /// top margin + @available(iOS 8.0, *) public var snp_topMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TopMargin) } /// bottom margin + @available(iOS 8.0, *) public var snp_bottomMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.BottomMargin) } /// leading margin + @available(iOS 8.0, *) public var snp_leadingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeadingMargin) } /// trailing margin + @available(iOS 8.0, *) public var snp_trailingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TrailingMargin) } /// centerX within margins + @available(iOS 8.0, *) public var snp_centerXWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterXWithinMargins) } /// centerY within margins + @available(iOS 8.0, *) public var snp_centerYWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterYWithinMargins) } #endif @@ -110,9 +119,11 @@ public extension View { #if os(iOS) // top + left + bottom + right margins + @available(iOS 8.0, *) public var snp_margins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Margins) } // centerX + centerY within margins + @available(iOS 8.0, *) public var snp_centerWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterWithinMargins) } #endif