Enforce availablility for iOS 8.0+ Attributes

This commit is contained in:
Robert Payne 2015-09-19 12:21:42 +12:00
parent 1754ffd536
commit 210bab97c7
4 changed files with 54 additions and 0 deletions

View File

@ -67,14 +67,23 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType {
internal static var Baseline: ConstraintAttributes { return self.init(1024) } internal static var Baseline: ConstraintAttributes { return self.init(1024) }
#if os(iOS) #if os(iOS)
@available(iOS 8.0, *)
internal static var FirstBaseline: ConstraintAttributes { return self.init(2048) } internal static var FirstBaseline: ConstraintAttributes { return self.init(2048) }
@available(iOS 8.0, *)
internal static var LeftMargin: ConstraintAttributes { return self.init(4096) } internal static var LeftMargin: ConstraintAttributes { return self.init(4096) }
@available(iOS 8.0, *)
internal static var RightMargin: ConstraintAttributes { return self.init(8192) } internal static var RightMargin: ConstraintAttributes { return self.init(8192) }
@available(iOS 8.0, *)
internal static var TopMargin: ConstraintAttributes { return self.init(16384) } internal static var TopMargin: ConstraintAttributes { return self.init(16384) }
@available(iOS 8.0, *)
internal static var BottomMargin: ConstraintAttributes { return self.init(32768) } internal static var BottomMargin: ConstraintAttributes { return self.init(32768) }
@available(iOS 8.0, *)
internal static var LeadingMargin: ConstraintAttributes { return self.init(65536) } internal static var LeadingMargin: ConstraintAttributes { return self.init(65536) }
@available(iOS 8.0, *)
internal static var TrailingMargin: ConstraintAttributes { return self.init(131072) } internal static var TrailingMargin: ConstraintAttributes { return self.init(131072) }
@available(iOS 8.0, *)
internal static var CenterXWithinMargins: ConstraintAttributes { return self.init(262144) } internal static var CenterXWithinMargins: ConstraintAttributes { return self.init(262144) }
@available(iOS 8.0, *)
internal static var CenterYWithinMargins: ConstraintAttributes { return self.init(524288) } internal static var CenterYWithinMargins: ConstraintAttributes { return self.init(524288) }
#endif #endif
@ -85,7 +94,9 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType {
internal static var Center: ConstraintAttributes { return self.init(768) } internal static var Center: ConstraintAttributes { return self.init(768) }
#if os(iOS) #if os(iOS)
@available(iOS 8.0, *)
internal static var Margins: ConstraintAttributes { return self.init(61440) } internal static var Margins: ConstraintAttributes { return self.init(61440) }
@available(iOS 8.0, *)
internal static var CenterWithinMargins: ConstraintAttributes { return self.init(786432) } internal static var CenterWithinMargins: ConstraintAttributes { return self.init(786432) }
#endif #endif
@ -125,6 +136,9 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType {
attrs.append(.Baseline) attrs.append(.Baseline)
} }
#if os(iOS) #if os(iOS)
guard #available(iOS 8.0, *) else {
fatalError("Constrant attribute unavaialble for running platform and deployment target.")
}
if (self.contains(ConstraintAttributes.FirstBaseline)) { if (self.contains(ConstraintAttributes.FirstBaseline)) {
attrs.append(.FirstBaseline) attrs.append(.FirstBaseline)
} }

View File

@ -153,14 +153,23 @@ public protocol ConstraintDescriptionExtendable: ConstraintDescriptionRelatable
var baseline: ConstraintDescriptionExtendable { get } var baseline: ConstraintDescriptionExtendable { get }
#if os(iOS) #if os(iOS)
@available(iOS 8.0, *)
var firstBaseline: ConstraintDescriptionExtendable { get } var firstBaseline: ConstraintDescriptionExtendable { get }
@available(iOS 8.0, *)
var leftMargin: ConstraintDescriptionExtendable { get } var leftMargin: ConstraintDescriptionExtendable { get }
@available(iOS 8.0, *)
var rightMargin: ConstraintDescriptionExtendable { get } var rightMargin: ConstraintDescriptionExtendable { get }
@available(iOS 8.0, *)
var topMargin: ConstraintDescriptionExtendable { get } var topMargin: ConstraintDescriptionExtendable { get }
@available(iOS 8.0, *)
var bottomMargin: ConstraintDescriptionExtendable { get } var bottomMargin: ConstraintDescriptionExtendable { get }
@available(iOS 8.0, *)
var leadingMargin: ConstraintDescriptionExtendable { get } var leadingMargin: ConstraintDescriptionExtendable { get }
@available(iOS 8.0, *)
var trailingMargin: ConstraintDescriptionExtendable { get } var trailingMargin: ConstraintDescriptionExtendable { get }
@available(iOS 8.0, *)
var centerXWithinMargins: ConstraintDescriptionExtendable { get } var centerXWithinMargins: ConstraintDescriptionExtendable { get }
@available(iOS 8.0, *)
var centerYWithinMargins: ConstraintDescriptionExtendable { get } var centerYWithinMargins: ConstraintDescriptionExtendable { get }
#endif #endif
} }
@ -183,14 +192,23 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain
internal var baseline: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.Baseline) } internal var baseline: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.Baseline) }
#if os(iOS) #if os(iOS)
@available(iOS 8.0, *)
internal var firstBaseline: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.FirstBaseline) } internal var firstBaseline: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.FirstBaseline) }
@available(iOS 8.0, *)
internal var leftMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.LeftMargin) } internal var leftMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.LeftMargin) }
@available(iOS 8.0, *)
internal var rightMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.RightMargin) } internal var rightMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.RightMargin) }
@available(iOS 8.0, *)
internal var topMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.TopMargin) } internal var topMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.TopMargin) }
@available(iOS 8.0, *)
internal var bottomMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.BottomMargin) } internal var bottomMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.BottomMargin) }
@available(iOS 8.0, *)
internal var leadingMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.LeadingMargin) } internal var leadingMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.LeadingMargin) }
@available(iOS 8.0, *)
internal var trailingMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.TrailingMargin) } internal var trailingMargin: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.TrailingMargin) }
@available(iOS 8.0, *)
internal var centerXWithinMargins: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.CenterXWithinMargins) } internal var centerXWithinMargins: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.CenterXWithinMargins) }
@available(iOS 8.0, *)
internal var centerYWithinMargins: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.CenterYWithinMargins) } internal var centerYWithinMargins: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.CenterYWithinMargins) }
#endif #endif

View File

@ -68,30 +68,39 @@ public class ConstraintMaker {
#if os(iOS) #if os(iOS)
/// firse baseline position /// firse baseline position
@available(iOS 8.0, *)
public var firstBaseline: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.FirstBaseline) } public var firstBaseline: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.FirstBaseline) }
/// left margin /// left margin
@available(iOS 8.0, *)
public var leftMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.LeftMargin) } public var leftMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.LeftMargin) }
/// right margin /// right margin
@available(iOS 8.0, *)
public var rightMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.RightMargin) } public var rightMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.RightMargin) }
/// top margin /// top margin
@available(iOS 8.0, *)
public var topMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.TopMargin) } public var topMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.TopMargin) }
/// bottom margin /// bottom margin
@available(iOS 8.0, *)
public var bottomMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.BottomMargin) } public var bottomMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.BottomMargin) }
/// leading margin /// leading margin
@available(iOS 8.0, *)
public var leadingMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.LeadingMargin) } public var leadingMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.LeadingMargin) }
/// trailing margin /// trailing margin
@available(iOS 8.0, *)
public var trailingMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.TrailingMargin) } public var trailingMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.TrailingMargin) }
/// centerX within margins /// centerX within margins
@available(iOS 8.0, *)
public var centerXWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterXWithinMargins) } public var centerXWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterXWithinMargins) }
/// centerY within margins /// centerY within margins
@available(iOS 8.0, *)
public var centerYWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterYWithinMargins) } public var centerYWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterYWithinMargins) }
#endif #endif
@ -108,9 +117,11 @@ public class ConstraintMaker {
#if os(iOS) #if os(iOS)
// top + left + bottom + right margins // top + left + bottom + right margins
@available(iOS 8.0, *)
public var margins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Margins) } public var margins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Margins) }
// centerX + centerY within margins // centerX + centerY within margins
@available(iOS 8.0, *)
public var centerWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterWithinMargins) } public var centerWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterWithinMargins) }
#endif #endif

View File

@ -70,30 +70,39 @@ public extension View {
#if os(iOS) #if os(iOS)
/// first baseline position /// first baseline position
@available(iOS 8.0, *)
public var snp_firstBaseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.FirstBaseline) } public var snp_firstBaseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.FirstBaseline) }
/// left margin /// left margin
@available(iOS 8.0, *)
public var snp_leftMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeftMargin) } public var snp_leftMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeftMargin) }
/// right margin /// right margin
@available(iOS 8.0, *)
public var snp_rightMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.RightMargin) } public var snp_rightMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.RightMargin) }
/// top margin /// top margin
@available(iOS 8.0, *)
public var snp_topMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TopMargin) } public var snp_topMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TopMargin) }
/// bottom margin /// bottom margin
@available(iOS 8.0, *)
public var snp_bottomMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.BottomMargin) } public var snp_bottomMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.BottomMargin) }
/// leading margin /// leading margin
@available(iOS 8.0, *)
public var snp_leadingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeadingMargin) } public var snp_leadingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeadingMargin) }
/// trailing margin /// trailing margin
@available(iOS 8.0, *)
public var snp_trailingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TrailingMargin) } public var snp_trailingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TrailingMargin) }
/// centerX within margins /// centerX within margins
@available(iOS 8.0, *)
public var snp_centerXWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterXWithinMargins) } public var snp_centerXWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterXWithinMargins) }
/// centerY within margins /// centerY within margins
@available(iOS 8.0, *)
public var snp_centerYWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterYWithinMargins) } public var snp_centerYWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterYWithinMargins) }
#endif #endif
@ -110,9 +119,11 @@ public extension View {
#if os(iOS) #if os(iOS)
// top + left + bottom + right margins // top + left + bottom + right margins
@available(iOS 8.0, *)
public var snp_margins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Margins) } public var snp_margins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Margins) }
// centerX + centerY within margins // centerX + centerY within margins
@available(iOS 8.0, *)
public var snp_centerWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterWithinMargins) } public var snp_centerWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterWithinMargins) }
#endif #endif