From dce953eba6462f0598dae52b351615f4948f25a2 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 17 Jun 2015 23:09:54 +1200 Subject: [PATCH 1/4] Updated for Swift 2.0 --- SnapKit.xcodeproj/project.pbxproj | 32 +++++++++---------- .../xcschemes/SnapKit OSX.xcscheme | 5 ++- .../xcschemes/SnapKit iOS.xcscheme | 5 ++- Source/Constraint.swift | 16 +++++----- Source/ConstraintMaker.swift | 18 ++--------- Source/Debugging.swift | 4 +-- Source/Info.plist | 2 +- Source/View+SnapKit.swift | 2 +- Tests/Info.plist | 2 +- Tests/Tests.swift | 2 +- 10 files changed, 40 insertions(+), 48 deletions(-) diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index 3e10278..4b6c8f7 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -279,7 +279,8 @@ DDC9FD8D1981B4DD009612C7 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0600; + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 0700; ORGANIZATIONNAME = "SnapKit Team"; TargetAttributes = { EEBCC9D719CC627D0083B827 = { @@ -433,6 +434,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -506,6 +508,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SnapKit; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; @@ -526,6 +529,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SnapKit; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; @@ -537,12 +541,10 @@ EEBCC9EC19CC627E0083B827 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -550,12 +552,10 @@ EEBCC9ED19CC627E0083B827 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -578,6 +578,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SnapKit; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -602,6 +603,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SnapKit; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -615,13 +617,11 @@ isa = XCBuildConfiguration; buildSettings = { COMBINE_HIDPI_IMAGES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(DEVELOPER_FRAMEWORKS_DIR)", - "$(inherited)", - ); + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; }; @@ -633,13 +633,11 @@ COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - FRAMEWORK_SEARCH_PATHS = ( - "$(DEVELOPER_FRAMEWORKS_DIR)", - "$(inherited)", - ); + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; }; diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme index a6be18a..3ffad95 100644 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme @@ -1,6 +1,6 @@ + + + + [LayoutConstraint] { - return self.installOnView(updateExisting: false) + return self.installOnViewUpdatingExisting(false) } internal override func uninstall() -> Void { @@ -191,10 +191,10 @@ internal class ConcreteConstraint: Constraint { self.priority = priority } - internal func installOnView(updateExisting: Bool = false) -> [LayoutConstraint] { + internal func installOnViewUpdatingExisting(updateExisting: Bool = false) -> [LayoutConstraint] { var installOnView: View? = nil if self.toItem.view != nil { - installOnView = closestCommonSuperviewBetween(self.fromItem.view, self.toItem.view) + installOnView = closestCommonSuperviewFromView(self.fromItem.view, toView: self.toItem.view) if installOnView == nil { NSException(name: "Cannot Install Constraint", reason: "No common superview between views", userInfo: nil).raise() return [] @@ -236,7 +236,7 @@ internal class ConcreteConstraint: Constraint { let layoutToAttribute = (layoutToAttributes.count > 0) ? layoutToAttributes[0] : layoutFromAttribute // get layout constant - var layoutConstant: CGFloat = layoutToAttribute.snp_constantForValue(self.constant) + let layoutConstant: CGFloat = layoutToAttribute.snp_constantForValue(self.constant) // get layout to var layoutTo: View? = self.toItem.view @@ -266,7 +266,7 @@ internal class ConcreteConstraint: Constraint { // special logic for updating if updateExisting { // get existing constraints for this view - let existingLayoutConstraints = reverse(layoutFrom!.snp_installedLayoutConstraints) + let existingLayoutConstraints = layoutFrom!.snp_installedLayoutConstraints.reverse() // array that will contain only new layout constraints to keep var newLayoutConstraintsToKeep = [LayoutConstraint]() @@ -330,7 +330,7 @@ internal class ConcreteConstraint: Constraint { // remove the constraints from the from item view if let fromView = self.fromItem.view { fromView.snp_installedLayoutConstraints = fromView.snp_installedLayoutConstraints.filter { - return !contains(installedLayoutConstraints, $0) + return !installedLayoutConstraints.contains($0) } } } @@ -432,11 +432,11 @@ private extension NSLayoutAttribute { } } -private func closestCommonSuperviewBetween(fromView: View?, toView: View?) -> View? { +private func closestCommonSuperviewFromView(fromView: View?, toView: View?) -> View? { var views = Set() var fromView = fromView var toView = toView - do { + repeat { if let view = toView { if views.contains(view) { return view diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index 746c49f..04214a0 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -137,48 +137,36 @@ public class ConstraintMaker { } internal class func makeConstraints(view: View, @noescape closure: (make: ConstraintMaker) -> Void) { - #if os(iOS) - view.setTranslatesAutoresizingMaskIntoConstraints(false) - #else view.translatesAutoresizingMaskIntoConstraints = false - #endif let maker = ConstraintMaker(view: view) closure(make: maker) let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint } for constraint in constraints { - constraint.installOnView(updateExisting: false) + constraint.installOnViewUpdatingExisting(false) } } internal class func remakeConstraints(view: View, @noescape closure: (make: ConstraintMaker) -> Void) { - #if os(iOS) - view.setTranslatesAutoresizingMaskIntoConstraints(false) - #else view.translatesAutoresizingMaskIntoConstraints = false - #endif let maker = ConstraintMaker(view: view) closure(make: maker) self.removeConstraints(view) let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint } for constraint in constraints { - constraint.installOnView(updateExisting: false) + constraint.installOnViewUpdatingExisting(false) } } internal class func updateConstraints(view: View, @noescape closure: (make: ConstraintMaker) -> Void) { - #if os(iOS) - view.setTranslatesAutoresizingMaskIntoConstraints(false) - #else view.translatesAutoresizingMaskIntoConstraints = false - #endif let maker = ConstraintMaker(view: view) closure(make: maker) let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint} for constraint in constraints { - constraint.installOnView(updateExisting: true) + constraint.installOnViewUpdatingExisting(true) } } diff --git a/Source/Debugging.swift b/Source/Debugging.swift index 8a96a74..b49b253 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -37,7 +37,7 @@ public extension View { return objc_getAssociatedObject(self, &labelKey) as? String } set { - objc_setAssociatedObject(self, &labelKey, newValue, objc_AssociationPolicy(OBJC_ASSOCIATION_COPY_NONATOMIC)) + objc_setAssociatedObject(self, &labelKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_COPY_NONATOMIC) } } @@ -53,7 +53,7 @@ public extension LayoutConstraint { return objc_getAssociatedObject(self, &labelKey) as? String } set { - objc_setAssociatedObject(self, &labelKey, newValue, objc_AssociationPolicy(OBJC_ASSOCIATION_COPY_NONATOMIC)) + objc_setAssociatedObject(self, &labelKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_COPY_NONATOMIC) } } diff --git a/Source/Info.plist b/Source/Info.plist index 9659480..d3de8ee 100644 --- a/Source/Info.plist +++ b/Source/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - io.snapkit.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Source/View+SnapKit.swift b/Source/View+SnapKit.swift index 5141879..0fc39a8 100644 --- a/Source/View+SnapKit.swift +++ b/Source/View+SnapKit.swift @@ -172,7 +172,7 @@ public extension View { return [] } set { - objc_setAssociatedObject(self, &installedLayoutConstraintsKey, newValue, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC)) + objc_setAssociatedObject(self, &installedLayoutConstraintsKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) } } } diff --git a/Tests/Info.plist b/Tests/Info.plist index e06ec80..ba72822 100644 --- a/Tests/Info.plist +++ b/Tests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - io.snapkit.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Tests/Tests.swift b/Tests/Tests.swift index c7d8c72..96bc368 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -2,7 +2,7 @@ import UIKit typealias View = UIView extension View { - var snp_constraints: [AnyObject] { return self.constraints() } + var snp_constraints: [AnyObject] { return self.constraints } } #else import AppKit From ee3e1283fd58c945de677737c7b9df1e8d464a50 Mon Sep 17 00:00:00 2001 From: Ben Jones Date: Wed, 24 Jun 2015 11:28:28 -0700 Subject: [PATCH 2/4] Fixes for Swift 2.0 b2 --- Source/Constraint.swift | 2 + Source/ConstraintAttributes.swift | 106 +++++++++++++++--------------- Source/Debugging.swift | 1 + 3 files changed, 56 insertions(+), 53 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 5a1dea7..e3ca732 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -400,6 +400,7 @@ private extension NSLayoutAttribute { case .Leading: return point.x case .Trailing: return point.x case .Width, .Height, .NotAnAttribute: return CGFloat(0) + default: return CGFloat(0) } #endif } @@ -424,6 +425,7 @@ private extension NSLayoutAttribute { case .Leading: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.left : -insets.right case .Trailing: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.right : -insets.left case .Width, .Height, .NotAnAttribute: return CGFloat(0) + default: return CGFloat(0) } #endif } diff --git a/Source/ConstraintAttributes.swift b/Source/ConstraintAttributes.swift index d20cd95..a16a04e 100644 --- a/Source/ConstraintAttributes.swift +++ b/Source/ConstraintAttributes.swift @@ -30,7 +30,7 @@ import AppKit /** Used to define `NSLayoutAttributes` in a more concise and composite manner */ -internal struct ConstraintAttributes: RawOptionSetType, BooleanType { +internal struct ConstraintAttributes: OptionSetType, BooleanType { internal init(rawValue: UInt) { self.rawValue = rawValue @@ -43,113 +43,113 @@ internal struct ConstraintAttributes: RawOptionSetType, BooleanType { } internal private(set) var rawValue: UInt - internal static var allZeros: ConstraintAttributes { return self(0) } - internal static func convertFromNilLiteral() -> ConstraintAttributes { return self(0) } + internal static var allZeros: ConstraintAttributes { return self.init(0) } + internal static func convertFromNilLiteral() -> ConstraintAttributes { return self.init(0) } internal var boolValue: Bool { return self.rawValue != 0 } internal func toRaw() -> UInt { return self.rawValue } - internal static func fromRaw(raw: UInt) -> ConstraintAttributes? { return self(raw) } - internal static func fromMask(raw: UInt) -> ConstraintAttributes { return self(raw) } + internal static func fromRaw(raw: UInt) -> ConstraintAttributes? { return self.init(raw) } + internal static func fromMask(raw: UInt) -> ConstraintAttributes { return self.init(raw) } // normal - internal static var None: ConstraintAttributes { return self(0) } - internal static var Left: ConstraintAttributes { return self(1) } - internal static var Top: ConstraintAttributes { return self(2) } - internal static var Right: ConstraintAttributes { return self(4) } - internal static var Bottom: ConstraintAttributes { return self(8) } - internal static var Leading: ConstraintAttributes { return self(16) } - internal static var Trailing: ConstraintAttributes { return self(32) } - internal static var Width: ConstraintAttributes { return self(64) } - internal static var Height: ConstraintAttributes { return self(128) } - internal static var CenterX: ConstraintAttributes { return self(256) } - internal static var CenterY: ConstraintAttributes { return self(512) } - internal static var Baseline: ConstraintAttributes { return self(1024) } + internal static var None: ConstraintAttributes { return self.init(0) } + internal static var Left: ConstraintAttributes { return self.init(1) } + internal static var Top: ConstraintAttributes { return self.init(2) } + internal static var Right: ConstraintAttributes { return self.init(4) } + internal static var Bottom: ConstraintAttributes { return self.init(8) } + internal static var Leading: ConstraintAttributes { return self.init(16) } + internal static var Trailing: ConstraintAttributes { return self.init(32) } + internal static var Width: ConstraintAttributes { return self.init(64) } + internal static var Height: ConstraintAttributes { return self.init(128) } + internal static var CenterX: ConstraintAttributes { return self.init(256) } + internal static var CenterY: ConstraintAttributes { return self.init(512) } + internal static var Baseline: ConstraintAttributes { return self.init(1024) } #if os(iOS) - internal static var FirstBaseline: ConstraintAttributes { return self(2048) } - internal static var LeftMargin: ConstraintAttributes { return self(4096) } - internal static var RightMargin: ConstraintAttributes { return self(8192) } - internal static var TopMargin: ConstraintAttributes { return self(16384) } - internal static var BottomMargin: ConstraintAttributes { return self(32768) } - internal static var LeadingMargin: ConstraintAttributes { return self(65536) } - internal static var TrailingMargin: ConstraintAttributes { return self(131072) } - internal static var CenterXWithinMargins: ConstraintAttributes { return self(262144) } - internal static var CenterYWithinMargins: ConstraintAttributes { return self(524288) } + internal static var FirstBaseline: ConstraintAttributes { return self.init(2048) } + internal static var LeftMargin: ConstraintAttributes { return self.init(4096) } + internal static var RightMargin: ConstraintAttributes { return self.init(8192) } + internal static var TopMargin: ConstraintAttributes { return self.init(16384) } + internal static var BottomMargin: ConstraintAttributes { return self.init(32768) } + internal static var LeadingMargin: ConstraintAttributes { return self.init(65536) } + internal static var TrailingMargin: ConstraintAttributes { return self.init(131072) } + internal static var CenterXWithinMargins: ConstraintAttributes { return self.init(262144) } + internal static var CenterYWithinMargins: ConstraintAttributes { return self.init(524288) } #endif // aggregates - internal static var Edges: ConstraintAttributes { return self(15) } - internal static var Size: ConstraintAttributes { return self(192) } - internal static var Center: ConstraintAttributes { return self(768) } + internal static var Edges: ConstraintAttributes { return self.init(15) } + internal static var Size: ConstraintAttributes { return self.init(192) } + internal static var Center: ConstraintAttributes { return self.init(768) } #if os(iOS) - internal static var Margins: ConstraintAttributes { return self(61440) } - internal static var CenterWithinMargins: ConstraintAttributes { return self(786432) } + internal static var Margins: ConstraintAttributes { return self.init(61440) } + internal static var CenterWithinMargins: ConstraintAttributes { return self.init(786432) } #endif internal var layoutAttributes:[NSLayoutAttribute] { var attrs = [NSLayoutAttribute]() - if (self & ConstraintAttributes.Left) { + if (self.contains(ConstraintAttributes.Left)) { attrs.append(.Left) } - if (self & ConstraintAttributes.Top) { + if (self.contains(ConstraintAttributes.Top)) { attrs.append(.Top) } - if (self & ConstraintAttributes.Right) { + if (self.contains(ConstraintAttributes.Right)) { attrs.append(.Right) } - if (self & ConstraintAttributes.Bottom) { + if (self.contains(ConstraintAttributes.Bottom)) { attrs.append(.Bottom) } - if (self & ConstraintAttributes.Leading) { + if (self.contains(ConstraintAttributes.Leading)) { attrs.append(.Leading) } - if (self & ConstraintAttributes.Trailing) { + if (self.contains(ConstraintAttributes.Trailing)) { attrs.append(.Trailing) } - if (self & ConstraintAttributes.Width) { + if (self.contains(ConstraintAttributes.Width)) { attrs.append(.Width) } - if (self & ConstraintAttributes.Height) { + if (self.contains(ConstraintAttributes.Height)) { attrs.append(.Height) } - if (self & ConstraintAttributes.CenterX) { + if (self.contains(ConstraintAttributes.CenterX)) { attrs.append(.CenterX) } - if (self & ConstraintAttributes.CenterY) { + if (self.contains(ConstraintAttributes.CenterY)) { attrs.append(.CenterY) } - if (self & ConstraintAttributes.Baseline) { + if (self.contains(ConstraintAttributes.Baseline)) { attrs.append(.Baseline) } #if os(iOS) - if (self & ConstraintAttributes.FirstBaseline) { + if (self.contains(ConstraintAttributes.FirstBaseline)) { attrs.append(.FirstBaseline) } - if (self & ConstraintAttributes.LeftMargin) { + if (self.contains(ConstraintAttributes.LeftMargin)) { attrs.append(.LeftMargin) } - if (self & ConstraintAttributes.RightMargin) { + if (self.contains(ConstraintAttributes.RightMargin)) { attrs.append(.RightMargin) } - if (self & ConstraintAttributes.TopMargin) { + if (self.contains(ConstraintAttributes.TopMargin)) { attrs.append(.TopMargin) } - if (self & ConstraintAttributes.BottomMargin) { + if (self.contains(ConstraintAttributes.BottomMargin)) { attrs.append(.BottomMargin) } - if (self & ConstraintAttributes.LeadingMargin) { + if (self.contains(ConstraintAttributes.LeadingMargin)) { attrs.append(.LeadingMargin) } - if (self & ConstraintAttributes.TrailingMargin) { + if (self.contains(ConstraintAttributes.TrailingMargin)) { attrs.append(.TrailingMargin) } - if (self & ConstraintAttributes.CenterXWithinMargins) { + if (self.contains(ConstraintAttributes.CenterXWithinMargins)) { attrs.append(.CenterXWithinMargins) } - if (self & ConstraintAttributes.CenterYWithinMargins) { + if (self.contains(ConstraintAttributes.CenterYWithinMargins)) { attrs.append(.CenterYWithinMargins) } #endif @@ -157,10 +157,10 @@ internal struct ConstraintAttributes: RawOptionSetType, BooleanType { } } internal func +=(inout left: ConstraintAttributes, right: ConstraintAttributes) { - left = (left | right) + left = left.intersect(right) } internal func -=(inout left: ConstraintAttributes, right: ConstraintAttributes) { - left = left & ~right + left = left.subtract(right) } internal func ==(left: ConstraintAttributes, right: ConstraintAttributes) -> Bool { return left.rawValue == right.rawValue diff --git a/Source/Debugging.swift b/Source/Debugging.swift index b49b253..330302d 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -167,6 +167,7 @@ private extension NSLayoutAttribute { case .CenterX: return "centerX" case .CenterY: return "centerY" case .Baseline: return "baseline" + default: return "default" } #endif From c2eae8e90ae50c6ebb353699bc73cb979c78c9e0 Mon Sep 17 00:00:00 2001 From: Ben Jones Date: Wed, 24 Jun 2015 15:10:38 -0700 Subject: [PATCH 3/4] Handle new NSLayoutAttribute FirstBaseline that is introduced in OS X 10.11 for CGPoint or EdgeInsets --- Source/Constraint.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index e3ca732..0825ef1 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -400,7 +400,7 @@ private extension NSLayoutAttribute { case .Leading: return point.x case .Trailing: return point.x case .Width, .Height, .NotAnAttribute: return CGFloat(0) - default: return CGFloat(0) + case .FirstBaseline: return point.y } #endif } @@ -425,7 +425,7 @@ private extension NSLayoutAttribute { case .Leading: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.left : -insets.right case .Trailing: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.right : -insets.left case .Width, .Height, .NotAnAttribute: return CGFloat(0) - default: return CGFloat(0) + case .FirstBaseline: return insets.bottom } #endif } From ef024cf351c9b3b467434ae2a86b7d3e3c4bab9d Mon Sep 17 00:00:00 2001 From: Ben Jones Date: Thu, 25 Jun 2015 10:53:12 -0700 Subject: [PATCH 4/4] Change += and -= to use inPlace ops and += should be union --- Source/ConstraintAttributes.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/ConstraintAttributes.swift b/Source/ConstraintAttributes.swift index a16a04e..06b3dec 100644 --- a/Source/ConstraintAttributes.swift +++ b/Source/ConstraintAttributes.swift @@ -157,10 +157,10 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { } } internal func +=(inout left: ConstraintAttributes, right: ConstraintAttributes) { - left = left.intersect(right) + left.unionInPlace(right) } internal func -=(inout left: ConstraintAttributes, right: ConstraintAttributes) { - left = left.subtract(right) + left.subtractInPlace(right) } internal func ==(left: ConstraintAttributes, right: ConstraintAttributes) -> Bool { return left.rawValue == right.rawValue