Merge pull request #143 from devxoul/availability

Add availability check for iOS 8 and OS X 10.10 APIs.
This commit is contained in:
Robert Payne 2015-09-19 12:15:48 +12:00
commit 552b1520f3
2 changed files with 41 additions and 39 deletions

View File

@ -138,24 +138,24 @@ internal class ConcreteConstraint: Constraint {
}
internal override func activate() -> Void {
if NSLayoutConstraint.respondsToSelector("activateConstraints:") && self.installInfo != nil {
let layoutConstraints = self.installInfo!.layoutConstraints.allObjects as! [LayoutConstraint]
if layoutConstraints.count > 0 {
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
} else {
guard #available(iOS 8.0, OSX 10.10, *), self.installInfo != nil else {
self.install()
return
}
let layoutConstraints = self.installInfo!.layoutConstraints.allObjects as! [LayoutConstraint]
if layoutConstraints.count > 0 {
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
}
internal override func deactivate() -> Void {
if NSLayoutConstraint.respondsToSelector("deactivateConstraints:") && self.installInfo != nil {
let layoutConstraints = self.installInfo!.layoutConstraints.allObjects as! [LayoutConstraint]
if layoutConstraints.count > 0 {
NSLayoutConstraint.deactivateConstraints(layoutConstraints)
}
} else {
self.uninstall()
guard #available(iOS 8.0, OSX 10.10, *), self.installInfo != nil else {
self.install()
return
}
let layoutConstraints = self.installInfo!.layoutConstraints.allObjects as! [LayoutConstraint]
if layoutConstraints.count > 0 {
NSLayoutConstraint.deactivateConstraints(layoutConstraints)
}
}

View File

@ -125,32 +125,34 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType {
attrs.append(.Baseline)
}
#if os(iOS)
if (self.contains(ConstraintAttributes.FirstBaseline)) {
attrs.append(.FirstBaseline)
}
if (self.contains(ConstraintAttributes.LeftMargin)) {
attrs.append(.LeftMargin)
}
if (self.contains(ConstraintAttributes.RightMargin)) {
attrs.append(.RightMargin)
}
if (self.contains(ConstraintAttributes.TopMargin)) {
attrs.append(.TopMargin)
}
if (self.contains(ConstraintAttributes.BottomMargin)) {
attrs.append(.BottomMargin)
}
if (self.contains(ConstraintAttributes.LeadingMargin)) {
attrs.append(.LeadingMargin)
}
if (self.contains(ConstraintAttributes.TrailingMargin)) {
attrs.append(.TrailingMargin)
}
if (self.contains(ConstraintAttributes.CenterXWithinMargins)) {
attrs.append(.CenterXWithinMargins)
}
if (self.contains(ConstraintAttributes.CenterYWithinMargins)) {
attrs.append(.CenterYWithinMargins)
if #available(iOS 8.0, *) {
if (self.contains(ConstraintAttributes.FirstBaseline)) {
attrs.append(.FirstBaseline)
}
if (self.contains(ConstraintAttributes.LeftMargin)) {
attrs.append(.LeftMargin)
}
if (self.contains(ConstraintAttributes.RightMargin)) {
attrs.append(.RightMargin)
}
if (self.contains(ConstraintAttributes.TopMargin)) {
attrs.append(.TopMargin)
}
if (self.contains(ConstraintAttributes.BottomMargin)) {
attrs.append(.BottomMargin)
}
if (self.contains(ConstraintAttributes.LeadingMargin)) {
attrs.append(.LeadingMargin)
}
if (self.contains(ConstraintAttributes.TrailingMargin)) {
attrs.append(.TrailingMargin)
}
if (self.contains(ConstraintAttributes.CenterXWithinMargins)) {
attrs.append(.CenterXWithinMargins)
}
if (self.contains(ConstraintAttributes.CenterYWithinMargins)) {
attrs.append(.CenterYWithinMargins)
}
}
#endif
return attrs