From c6b3ecaad8078c9271972671c3bd75dbe2db8301 Mon Sep 17 00:00:00 2001 From: Ben Jones Date: Wed, 24 Jun 2015 11:28:28 -0700 Subject: [PATCH] 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 fdf12e1..6579f68 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -406,6 +406,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 } @@ -430,6 +431,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 574e463..02bb6a8 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -187,6 +187,7 @@ private extension NSLayoutAttribute { case .CenterX: return "centerX" case .CenterY: return "centerY" case .Baseline: return "baseline" + default: return "default" } #endif