diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 5b4c63d..d73ff5f 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -138,10 +138,16 @@ internal class ConcreteConstraint: Constraint { } internal override func activate() -> Void { - guard #available(iOS 8.0, OSX 10.10, *), self.installInfo != nil else { + guard self.installInfo != nil else { self.install() return } + #if SNAPKIT_DEPLOYMENT_LEGACY + guard #available(iOS 8.0, OSX 10.10, *) else { + self.install() + return + } + #endif let layoutConstraints = self.installInfo!.layoutConstraints.allObjects as! [LayoutConstraint] if layoutConstraints.count > 0 { NSLayoutConstraint.activateConstraints(layoutConstraints) @@ -149,10 +155,14 @@ internal class ConcreteConstraint: Constraint { } internal override func deactivate() -> Void { - guard #available(iOS 8.0, OSX 10.10, *), self.installInfo != nil else { - self.install() + guard self.installInfo != nil else { return } + #if SNAPKIT_DEPLOYMENT_LEGACY + guard #available(iOS 8.0, OSX 10.10, *) else { + return + } + #endif let layoutConstraints = self.installInfo!.layoutConstraints.allObjects as! [LayoutConstraint] if layoutConstraints.count > 0 { NSLayoutConstraint.deactivateConstraints(layoutConstraints) @@ -241,7 +251,11 @@ internal class ConcreteConstraint: Constraint { let layoutConstant: CGFloat = layoutToAttribute.snp_constantForValue(self.constant) // get layout to - var layoutTo: View? = self.toItem.view + #if os(iOS) + var layoutTo: AnyObject? = self.toItem.view ?? self.toItem.layoutSupport + #else + var layoutTo: AnyObject? = self.toItem.view + #endif if layoutTo == nil && layoutToAttribute != .Width && layoutToAttribute != .Height { layoutTo = installOnView } diff --git a/Source/ConstraintAttributes.swift b/Source/ConstraintAttributes.swift index 2af19a7..25f68e4 100644 --- a/Source/ConstraintAttributes.swift +++ b/Source/ConstraintAttributes.swift @@ -66,7 +66,6 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { internal static var CenterY: ConstraintAttributes { return self.init(512) } 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, *) @@ -85,7 +84,6 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { internal static var CenterXWithinMargins: ConstraintAttributes { return self.init(262144) } @available(iOS 8.0, *) internal static var CenterYWithinMargins: ConstraintAttributes { return self.init(524288) } - #endif // aggregates @@ -93,12 +91,11 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { internal static var Size: ConstraintAttributes { return self.init(192) } 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 internal var layoutAttributes:[NSLayoutAttribute] { var attrs = [NSLayoutAttribute]() @@ -135,10 +132,13 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { if (self.contains(ConstraintAttributes.Baseline)) { attrs.append(.Baseline) } + #if os(iOS) + #if SNAPKIT_DEPLOYMENT_LEGACY guard #available(iOS 8.0, *) else { - fatalError("Constrant attribute unavaialble for running platform and deployment target.") + return attrs } + #endif if (self.contains(ConstraintAttributes.FirstBaseline)) { attrs.append(.FirstBaseline) } @@ -167,6 +167,7 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { attrs.append(.CenterYWithinMargins) } #endif + return attrs } } diff --git a/Source/ConstraintDescription.swift b/Source/ConstraintDescription.swift index 0fdf888..d401192 100644 --- a/Source/ConstraintDescription.swift +++ b/Source/ConstraintDescription.swift @@ -93,9 +93,8 @@ public protocol ConstraintDescriptionRelatable: class { func equalTo(other: ConstraintItem) -> ConstraintDescriptionEditable func equalTo(other: View) -> ConstraintDescriptionEditable - #if os(iOS) - func equalTo(other: UILayoutSupport) -> ConstraintDescriptionEditable - #endif + @available(iOS 7.0, *) + func equalTo(other: LayoutSupport) -> ConstraintDescriptionEditable func equalTo(other: Float) -> ConstraintDescriptionEditable func equalTo(other: Double) -> ConstraintDescriptionEditable func equalTo(other: CGFloat) -> ConstraintDescriptionEditable @@ -107,9 +106,8 @@ public protocol ConstraintDescriptionRelatable: class { func lessThanOrEqualTo(other: ConstraintItem) -> ConstraintDescriptionEditable func lessThanOrEqualTo(other: View) -> ConstraintDescriptionEditable - #if os(iOS) - func lessThanOrEqualTo(other: UILayoutSupport) -> ConstraintDescriptionEditable - #endif + @available(iOS 7.0, *) + func lessThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable func lessThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable func lessThanOrEqualTo(other: Double) -> ConstraintDescriptionEditable func lessThanOrEqualTo(other: CGFloat) -> ConstraintDescriptionEditable @@ -121,9 +119,8 @@ public protocol ConstraintDescriptionRelatable: class { func greaterThanOrEqualTo(other: ConstraintItem) -> ConstraintDescriptionEditable func greaterThanOrEqualTo(other: View) -> ConstraintDescriptionEditable - #if os(iOS) - func greaterThanOrEqualTo(other: UILayoutSupport) -> ConstraintDescriptionEditable - #endif + @available(iOS 7.0, *) + func greaterThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable func greaterThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable func greaterThanOrEqualTo(other: Double) -> ConstraintDescriptionEditable func greaterThanOrEqualTo(other: CGFloat) -> ConstraintDescriptionEditable @@ -152,7 +149,6 @@ public protocol ConstraintDescriptionExtendable: ConstraintDescriptionRelatable var centerY: ConstraintDescriptionExtendable { get } var baseline: ConstraintDescriptionExtendable { get } - #if os(iOS) @available(iOS 8.0, *) var firstBaseline: ConstraintDescriptionExtendable { get } @available(iOS 8.0, *) @@ -171,7 +167,6 @@ public protocol ConstraintDescriptionExtendable: ConstraintDescriptionRelatable var centerXWithinMargins: ConstraintDescriptionExtendable { get } @available(iOS 8.0, *) var centerYWithinMargins: ConstraintDescriptionExtendable { get } - #endif } /** @@ -191,7 +186,6 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain internal var centerY: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.CenterY) } 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, *) @@ -210,7 +204,6 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain internal var centerXWithinMargins: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.CenterXWithinMargins) } @available(iOS 8.0, *) internal var centerYWithinMargins: ConstraintDescriptionExtendable { return self.addConstraint(ConstraintAttributes.CenterYWithinMargins) } - #endif // MARK: initializer @@ -227,11 +220,10 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain internal func equalTo(other: View) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .Equal) } - #if os(iOS) - internal func equalTo(other: UILayoutSupport) -> ConstraintDescriptionEditable { + @available(iOS 7.0, *) + internal func equalTo(other: LayoutSupport) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .Equal) } - #endif internal func equalTo(other: Float) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .Equal) } @@ -265,11 +257,10 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain internal func lessThanOrEqualTo(other: View) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .LessThanOrEqualTo) } - #if os(iOS) - internal func lessThanOrEqualTo(other: UILayoutSupport) -> ConstraintDescriptionEditable { + @available(iOS 7.0, *) + internal func lessThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .LessThanOrEqualTo) } - #endif internal func lessThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .LessThanOrEqualTo) } @@ -303,11 +294,10 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain internal func greaterThanOrEqualTo(other: View) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .GreaterThanOrEqualTo) } - #if os(iOS) - internal func greaterThanOrEqualTo(other: UILayoutSupport) -> ConstraintDescriptionEditable { + @available(iOS 7.0, *) + internal func greaterThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .GreaterThanOrEqualTo) } - #endif internal func greaterThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable { return self.constrainTo(other, relation: .GreaterThanOrEqualTo) } @@ -552,14 +542,11 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation) } - #if os(iOS) - - private func constrainTo(other: UILayoutSupport, relation: ConstraintRelation) -> ConstraintDescription { + @available(iOS 7.0, *) + private func constrainTo(other: LayoutSupport, relation: ConstraintRelation) -> ConstraintDescription { return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation) } - #endif - private func constrainTo(other: Float, relation: ConstraintRelation) -> ConstraintDescription { self.constant = other return constrainTo(ConstraintItem(object: nil, attributes: ConstraintAttributes.None), relation: relation) diff --git a/Source/ConstraintItem.swift b/Source/ConstraintItem.swift index 9dcfe11..ce0a366 100644 --- a/Source/ConstraintItem.swift +++ b/Source/ConstraintItem.swift @@ -44,13 +44,10 @@ public class ConstraintItem { return self.object as? View } - #if os(iOS) - - internal var layoutSupport: UILayoutSupport? { - return self.object as? UILayoutSupport + @available(iOS 7.0, *) + internal var layoutSupport: LayoutSupport? { + return self.object as? LayoutSupport } - - #endif } diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index 4cd6672..e18d87a 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -65,8 +65,6 @@ public class ConstraintMaker { /// baseline position public var baseline: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Baseline) } - #if os(iOS) - /// firse baseline position @available(iOS 8.0, *) public var firstBaseline: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.FirstBaseline) } @@ -103,8 +101,6 @@ public class ConstraintMaker { @available(iOS 8.0, *) public var centerYWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterYWithinMargins) } - #endif - /// top + left + bottom + right edges public var edges: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Edges) } @@ -114,8 +110,6 @@ public class ConstraintMaker { // centerX + centerY positions public var center: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Center) } - #if os(iOS) - // top + left + bottom + right margins @available(iOS 8.0, *) public var margins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Margins) } @@ -124,8 +118,6 @@ public class ConstraintMaker { @available(iOS 8.0, *) public var centerWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterWithinMargins) } - #endif - internal init(view: View, file: String, line: UInt) { self.view = view self.file = file diff --git a/Source/SnapKit.swift b/Source/SnapKit.swift index cf573dc..ea0d8ed 100644 --- a/Source/SnapKit.swift +++ b/Source/SnapKit.swift @@ -24,9 +24,11 @@ #if os(iOS) import UIKit public typealias InterfaceLayoutDirection = UIUserInterfaceLayoutDirection +public typealias LayoutSupport = UILayoutSupport #else import AppKit public typealias InterfaceLayoutDirection = NSUserInterfaceLayoutDirection +public class LayoutSupport {} #endif /** diff --git a/Source/View+SnapKit.swift b/Source/View+SnapKit.swift index ac9b771..9bf8903 100644 --- a/Source/View+SnapKit.swift +++ b/Source/View+SnapKit.swift @@ -67,8 +67,6 @@ public extension View { /// baseline position public var snp_baseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Baseline) } - #if os(iOS) - /// first baseline position @available(iOS 8.0, *) public var snp_firstBaseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.FirstBaseline) } @@ -105,8 +103,6 @@ public extension View { @available(iOS 8.0, *) public var snp_centerYWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterYWithinMargins) } - #endif - // top + left + bottom + right edges public var snp_edges: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Edges) } @@ -116,8 +112,6 @@ public extension View { // centerX + centerY positions public var snp_center: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Center) } - #if os(iOS) - // top + left + bottom + right margins @available(iOS 8.0, *) public var snp_margins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Margins) } @@ -126,8 +120,6 @@ public extension View { @available(iOS 8.0, *) public var snp_centerWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterWithinMargins) } - #endif - /** Prepares constraints with a `ConstraintMaker` and returns the made constraints but does not install them.