From 8e6219ef86c9467af71db691116cd819ca45ec07 Mon Sep 17 00:00:00 2001 From: Suyeol Jeon Date: Mon, 14 Sep 2015 22:31:55 +0900 Subject: [PATCH 1/2] Add availability check for iOS 8 attributes. --- Source/ConstraintAttributes.swift | 54 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/Source/ConstraintAttributes.swift b/Source/ConstraintAttributes.swift index 06b3dec..e19b18b 100644 --- a/Source/ConstraintAttributes.swift +++ b/Source/ConstraintAttributes.swift @@ -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 From ba03f22eb819c29c8d246800f7b74c24ac1eb695 Mon Sep 17 00:00:00 2001 From: Suyeol Jeon Date: Fri, 18 Sep 2015 13:18:28 +0900 Subject: [PATCH 2/2] Add availability check for iOS 8 and OS X 10.10 methods. - `NSLayoutConstraint.activateConstraints(_:)` - `NSLayoutConstraint.deactivateConstraints(_:)` --- Source/Constraint.swift | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 8bfc074..5b4c63d 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -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) } }