Merge pull request #118 from bendjones/swift-2.0

Fixes for Swift 2.0 b2
This commit is contained in:
Robert Payne 2015-06-26 09:31:02 +12:00
commit e9c9f6fe8e
3 changed files with 56 additions and 53 deletions

View File

@ -400,6 +400,7 @@ private extension NSLayoutAttribute {
case .Leading: return point.x
case .Trailing: return point.x
case .Width, .Height, .NotAnAttribute: return CGFloat(0)
case .FirstBaseline: return point.y
}
#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)
case .FirstBaseline: return insets.bottom
}
#endif
}

View File

@ -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.unionInPlace(right)
}
internal func -=(inout left: ConstraintAttributes, right: ConstraintAttributes) {
left = left & ~right
left.subtractInPlace(right)
}
internal func ==(left: ConstraintAttributes, right: ConstraintAttributes) -> Bool {
return left.rawValue == right.rawValue

View File

@ -167,6 +167,7 @@ private extension NSLayoutAttribute {
case .CenterX: return "centerX"
case .CenterY: return "centerY"
case .Baseline: return "baseline"
default: return "default"
}
#endif