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) }
#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)
}

View File

@ -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

View File

@ -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

View File

@ -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