From b739e44b5fefe9f91dfee132c1eb11b1022ff0e5 Mon Sep 17 00:00:00 2001 From: "Derrick J. Hathaway" Date: Thu, 11 Jun 2015 15:15:17 -0600 Subject: [PATCH] Adds Swift 2.0 support ran the swift migration utility. added `_` where necessary to prevent an API change (though maybe an API change should be considered in order to be consistent with the rest of Swift?) --- Cartfile.private | 4 +- Cartfile.resolved | 4 +- Cartography.xcodeproj/project.pbxproj | 11 ++- .../xcschemes/Cartography-Mac.xcscheme | 5 +- .../xcschemes/Cartography-iOS.xcscheme | 5 +- Cartography/Align.swift | 56 +++++------ Cartography/Compound.swift | 34 +++---- Cartography/ConstraintGroup.swift | 4 +- Cartography/Context.swift | 2 +- Cartography/Distribute.swift | 34 +++---- Cartography/Edges.swift | 32 +++---- Cartography/Info.plist | 2 +- Cartography/Layout.swift | 92 +++++++++---------- Cartography/Priority.swift | 12 +-- Cartography/Property.swift | 52 +++++------ Cartography/View.swift | 4 +- Cartography/ViewUtils.swift | 8 +- CartographyTests/Info.plist | 2 +- CartographyTests/TestView.swift | 4 +- CartographyTests/ViewHierarchySpec.swift | 4 +- 20 files changed, 193 insertions(+), 178 deletions(-) diff --git a/Cartfile.private b/Cartfile.private index 60c40d1..8aedc82 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,2 +1,2 @@ -github "Quick/Nimble" ~> 1.0 -github "Quick/Quick" ~> 0.3.1 +github "Quick/Nimble" "swift-2.0" +github "Quick/Quick" "swift-2.0" diff --git a/Cartfile.resolved b/Cartfile.resolved index caef36c..94da046 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -github "Quick/Nimble" "v1.0.0-rc.1" -github "Quick/Quick" "v0.3.1" +github "Quick/Nimble" "fa73feeb156d8af7f47ae94dde07f1f7847bb1a3" +github "Quick/Quick" "d69e14d987b8e6bfc6963a7383ec176401ba67ed" diff --git a/Cartography.xcodeproj/project.pbxproj b/Cartography.xcodeproj/project.pbxproj index 2983cf7..8088387 100644 --- a/Cartography.xcodeproj/project.pbxproj +++ b/Cartography.xcodeproj/project.pbxproj @@ -437,7 +437,8 @@ 54C96A08195063CD000CDD27 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0620; + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 0700; ORGANIZATIONNAME = "Robert Böhnke"; TargetAttributes = { 54C96A10195063CD000CDD27 = { @@ -720,6 +721,7 @@ INFOPLIST_FILE = Cartography/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = Cartography; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -743,6 +745,7 @@ INFOPLIST_FILE = Cartography/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = Cartography; SKIP_INSTALL = YES; }; @@ -764,6 +767,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = YES; OTHER_SWIFT_FLAGS = "-DTEST"; + PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -780,6 +784,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = NO; OTHER_SWIFT_FLAGS = "-DTEST"; + PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -807,6 +812,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = Cartography; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -833,6 +839,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = Cartography; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -857,6 +864,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; METAL_ENABLE_DEBUG_INFO = YES; OTHER_SWIFT_FLAGS = "-DTEST"; + PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; }; @@ -877,6 +885,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; METAL_ENABLE_DEBUG_INFO = NO; OTHER_SWIFT_FLAGS = "-DTEST"; + PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; }; diff --git a/Cartography.xcodeproj/xcshareddata/xcschemes/Cartography-Mac.xcscheme b/Cartography.xcodeproj/xcshareddata/xcschemes/Cartography-Mac.xcscheme index 1c671cb..0e5f52b 100644 --- a/Cartography.xcodeproj/xcshareddata/xcschemes/Cartography-Mac.xcscheme +++ b/Cartography.xcodeproj/xcshareddata/xcschemes/Cartography-Mac.xcscheme @@ -1,6 +1,6 @@ + + + + (attribute: LayoutProxy -> P, first: LayoutProxy, rest: [LayoutProxy]) -> [NSLayoutConstraint] { - return reduce(rest, []) { acc, current in + return rest.reduce([]) { acc, current in current.view.car_translatesAutoresizingMaskIntoConstraints = false return acc + [ attribute(first) == attribute(current) ] @@ -25,10 +25,10 @@ private func makeEqual(attribute: LayoutProxy -> P, first: /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func align(top first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return makeEqual({ $0.top }, first, rest) +public func align(top first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return makeEqual({ $0.top }, first: first, rest: rest) } /// Aligns multiple views by their right edge. @@ -36,10 +36,10 @@ public func align(top first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutCons /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func align(right first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return makeEqual({ $0.right }, first, rest) +public func align(right first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return makeEqual({ $0.right }, first: first, rest: rest) } /// Aligns multiple views by their bottom edge. @@ -47,10 +47,10 @@ public func align(right first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutCo /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func align(bottom first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return makeEqual({ $0.bottom }, first, rest) +public func align(bottom first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return makeEqual({ $0.bottom }, first: first, rest: rest) } /// Aligns multiple views by their left edge. @@ -58,10 +58,10 @@ public func align(bottom first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutC /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func align(left first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return makeEqual({ $0.left }, first, rest) +public func align(left first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return makeEqual({ $0.left }, first: first, rest: rest) } /// Aligns multiple views by their leading edge. @@ -69,10 +69,10 @@ public func align(left first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutCon /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func align(leading first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return makeEqual({ $0.leading }, first, rest) +public func align(leading first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return makeEqual({ $0.leading }, first: first, rest: rest) } /// Aligns multiple vies by their trailing edge. @@ -80,10 +80,10 @@ public func align(leading first: LayoutProxy, rest: LayoutProxy...) -> [NSLayout /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func align(trailing first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return makeEqual({ $0.trailing }, first, rest) +public func align(trailing first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return makeEqual({ $0.trailing }, first: first, rest: rest) } /// Aligns multiple views by their horizontal center. @@ -91,10 +91,10 @@ public func align(trailing first: LayoutProxy, rest: LayoutProxy...) -> [NSLayou /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func align(centerX first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return makeEqual({ $0.centerX }, first, rest) +public func align(centerX first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return makeEqual({ $0.centerX }, first: first, rest: rest) } /// Aligns multiple views by their vertical center. @@ -102,10 +102,10 @@ public func align(centerX first: LayoutProxy, rest: LayoutProxy...) -> [NSLayout /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func align(centerY first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return makeEqual({ $0.centerY }, first, rest) +public func align(centerY first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return makeEqual({ $0.centerY }, first: first, rest: rest) } /// Aligns multiple views by their baseline. @@ -113,8 +113,8 @@ public func align(centerY first: LayoutProxy, rest: LayoutProxy...) -> [NSLayout /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func align(baseline first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return makeEqual({ $0.baseline }, first, rest) +public func align(baseline first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return makeEqual({ $0.baseline }, first: first, rest: rest) } diff --git a/Cartography/Compound.swift b/Cartography/Compound.swift index 0447c5a..c492a1c 100644 --- a/Cartography/Compound.swift +++ b/Cartography/Compound.swift @@ -23,11 +23,11 @@ public protocol RelativeCompoundEquality : Compound { } /// Declares a property equal to a the result of an expression. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The expression. +/// - parameter rhs: The expression. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func == (lhs: P, rhs: Expression

) -> [NSLayoutConstraint] { return lhs.context.addConstraint(lhs, coefficients: rhs.coefficients, to: rhs.value) @@ -35,9 +35,9 @@ public func == (lhs: P, rhs: Expression

) -> [NSL /// Declares a property equal to another compound property. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The other property. +/// - parameter rhs: The other property. /// public func == (lhs: P, rhs: P) -> [NSLayoutConstraint] { return lhs.context.addConstraint(lhs, to: rhs) @@ -49,11 +49,11 @@ public protocol RelativeCompoundInequality : Compound { } /// Declares a property less than or equal to another compound property. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The other property. +/// - parameter rhs: The other property. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func <= (lhs: P, rhs: P) -> [NSLayoutConstraint] { return lhs.context.addConstraint(lhs, to: rhs, relation: NSLayoutRelation.LessThanOrEqual) @@ -61,11 +61,11 @@ public func <= (lhs: P, rhs: P) -> [NSLayoutConst /// Declares a property greater than or equal to another compound property. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The other property. +/// - parameter rhs: The other property. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func >= (lhs: P, rhs: P) -> [NSLayoutConstraint] { return lhs.context.addConstraint(lhs, to: rhs, relation: NSLayoutRelation.GreaterThanOrEqual) @@ -73,11 +73,11 @@ public func >= (lhs: P, rhs: P) -> [NSLayoutConst /// Declares a property less than or equal to the result of an expression. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The other property. +/// - parameter rhs: The other property. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func <= (lhs: P, rhs: Expression

) -> [NSLayoutConstraint] { return lhs.context.addConstraint(lhs, coefficients: rhs.coefficients, to: rhs.value, relation: NSLayoutRelation.LessThanOrEqual) @@ -85,11 +85,11 @@ public func <= (lhs: P, rhs: Expression

) -> [N /// Declares a property greater than or equal to the result of an expression. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The other property. +/// - parameter rhs: The other property. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func >= (lhs: P, rhs: Expression

) -> [NSLayoutConstraint] { return lhs.context.addConstraint(lhs, coefficients: rhs.coefficients, to: rhs.value, relation: NSLayoutRelation.GreaterThanOrEqual) diff --git a/Cartography/ConstraintGroup.swift b/Cartography/ConstraintGroup.swift index 1e0dc0d..d127c7a 100644 --- a/Cartography/ConstraintGroup.swift +++ b/Cartography/ConstraintGroup.swift @@ -11,8 +11,8 @@ import Foundation public class ConstraintGroup { private var constraints: [Constraint] = [] - @availability(OSX, introduced=10.10) - @availability(iOS, introduced=8.0) + @available(OSX, introduced=10.10) + @available(iOS, introduced=8.0) public var active: Bool { get { return constraints.map({ $0.layoutConstraint.active }).reduce(true) { $0 && $1 } diff --git a/Cartography/Context.swift b/Cartography/Context.swift index 3110891..8f57632 100644 --- a/Cartography/Context.swift +++ b/Cartography/Context.swift @@ -27,7 +27,7 @@ public class Context { constant: CGFloat(coefficients.constant)) if let to = to { - if let common = closestCommonAncestor(from.view, to.view ) { + if let common = closestCommonAncestor(from.view, b: to.view ) { constraints.append(Constraint(view: common, layoutConstraint: layoutConstraint)) } else { fatalError("No common superview found between \(from.view) and \(to.view)") diff --git a/Cartography/Distribute.swift b/Cartography/Distribute.swift index b362cb3..bcda0e3 100644 --- a/Cartography/Distribute.swift +++ b/Cartography/Distribute.swift @@ -17,8 +17,8 @@ typealias Accumulator = ([NSLayoutConstraint], LayoutProxy) private func reduce(first: LayoutProxy, rest: [LayoutProxy], combine: (LayoutProxy, LayoutProxy) -> NSLayoutConstraint) -> [NSLayoutConstraint] { rest.last?.view.car_translatesAutoresizingMaskIntoConstraints = false - return reduce(rest, ([], first)) { (acc, current) -> Accumulator in - var (constraints, previous) = acc + return rest.reduce(([], first)) { (acc, current) -> Accumulator in + let (constraints, previous) = acc return (constraints + [ combine(previous, current) ], current) }.0 @@ -29,13 +29,13 @@ private func reduce(first: LayoutProxy, rest: [LayoutProxy], combine: (LayoutPro /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :param: amount The distance between the views. -/// :param: views The views to distribute. +/// - parameter amount: The distance between the views. +/// - parameter views: The views to distribute. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func distribute(by amount: CGFloat, horizontally first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return reduce(first, rest) { $0.trailing == $1.leading - amount } +public func distribute(by amount: CGFloat, horizontally first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return reduce(first, rest: rest) { $0.trailing == $1.leading - amount } } /// Distributes multiple views horizontally from left to right. @@ -43,13 +43,13 @@ public func distribute(by amount: CGFloat, horizontally first: LayoutProxy, rest /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :param: amount The distance between the views. -/// :param: views The views to distribute. +/// - parameter amount: The distance between the views. +/// - parameter views: The views to distribute. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func distribute(by amount: CGFloat, leftToRight first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return reduce(first, rest) { $0.right == $1.left - amount } +public func distribute(by amount: CGFloat, leftToRight first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return reduce(first, rest: rest) { $0.right == $1.left - amount } } /// Distributes multiple views vertically. @@ -57,11 +57,11 @@ public func distribute(by amount: CGFloat, leftToRight first: LayoutProxy, rest: /// All views passed to this function will have /// their `translatesAutoresizingMaskIntoConstraints` properties set to `false`. /// -/// :param: amount The distance between the views. -/// :param: views The views to distribute. +/// - parameter amount: The distance between the views. +/// - parameter views: The views to distribute. /// -/// :returns: An array of `NSLayoutConstraint` instances. +/// - returns: An array of `NSLayoutConstraint` instances. /// -public func distribute(by amount: CGFloat, vertically first: LayoutProxy, rest: LayoutProxy...) -> [NSLayoutConstraint] { - return reduce(first, rest) { $0.bottom == $1.top - amount } +public func distribute(by amount: CGFloat, vertically first: LayoutProxy, _ rest: LayoutProxy...) -> [NSLayoutConstraint] { + return reduce(first, rest: rest) { $0.bottom == $1.top - amount } } diff --git a/Cartography/Edges.swift b/Cartography/Edges.swift index 688bc0a..f2bcb42 100644 --- a/Cartography/Edges.swift +++ b/Cartography/Edges.swift @@ -24,40 +24,40 @@ public struct Edges: Compound, RelativeCompoundEquality, RelativeCompoundInequal /// Insets all edges. /// -/// :param: edges The edges to inset. -/// :param: all The amount by which to inset all edges, in points. +/// - parameter edges: The edges to inset. +/// - parameter all: The amount by which to inset all edges, in points. /// -/// :returns: A new expression with the inset edges. +/// - returns: A new expression with the inset edges. /// -public func inset(edges: Edges, all: CGFloat) -> Expression { +public func inset(_ edges: Edges, _ all: CGFloat) -> Expression { return inset(edges, all, all, all, all) } /// Insets the horizontal and vertical edges. /// -/// :param: edges The edges to inset. -/// :param: horizontal The amount by which to inset the horizontal edges, in +/// - parameter edges: The edges to inset. +/// - parameter horizontal: The amount by which to inset the horizontal edges, in /// points. -/// :param: vertical The amount by which to inset the vertical edges, in +/// - parameter vertical: The amount by which to inset the vertical edges, in /// points. /// -/// :returns: A new expression with the inset edges. +/// - returns: A new expression with the inset edges. /// -public func inset(edges: Edges, horizontal: CGFloat, vertical: CGFloat) -> Expression { +public func inset(_ edges: Edges, _ horizontal: CGFloat, _ vertical: CGFloat) -> Expression { return inset(edges, vertical, horizontal, vertical, horizontal) } /// Insets edges individually. /// -/// :param: edges The edges to inset. -/// :param: top The amount by which to inset the top edge, in points. -/// :param: leading The amount by which to inset the leading edge, in points. -/// :param: bottom The amount by which to inset the bottom edge, in points. -/// :param: trailing The amount by which to inset the trailing edge, in points. +/// - parameter edges: The edges to inset. +/// - parameter top: The amount by which to inset the top edge, in points. +/// - parameter leading: The amount by which to inset the leading edge, in points. +/// - parameter bottom: The amount by which to inset the bottom edge, in points. +/// - parameter trailing: The amount by which to inset the trailing edge, in points. /// -/// :returns: A new expression with the inset edges. +/// - returns: A new expression with the inset edges. /// -public func inset(edges: Edges, top: CGFloat, leading: CGFloat, bottom: CGFloat, trailing: CGFloat) -> Expression { +public func inset(_ edges: Edges, _ top: CGFloat, _ leading: CGFloat, _ bottom: CGFloat, _ trailing: CGFloat) -> Expression { return Expression(edges, [ Coefficients(1, top), Coefficients(1, leading), diff --git a/Cartography/Info.plist b/Cartography/Info.plist index 32ba1b1..7812205 100644 --- a/Cartography/Info.plist +++ b/Cartography/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.robertboehnke.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Cartography/Layout.swift b/Cartography/Layout.swift index c25500a..b038969 100644 --- a/Cartography/Layout.swift +++ b/Cartography/Layout.swift @@ -12,11 +12,11 @@ import Foundation /// /// The views will have its layout updated after this call. /// -/// :param: view The view to layout. -/// :param: replace The `ConstraintGroup` whose constraints should be replaced. -/// :param: block A block that declares the layout for `view`. +/// - parameter view: The view to layout. +/// - parameter replace: The `ConstraintGroup` whose constraints should be replaced. +/// - parameter block: A block that declares the layout for `view`. /// -public func layout(view: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: LayoutProxy -> ()) -> ConstraintGroup { +public func layout(_ view: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: LayoutProxy -> ()) -> ConstraintGroup { let context = Context() block(LayoutProxy(context, view)) group.replaceConstraints(context.constraints, performLayout: true) @@ -28,12 +28,12 @@ public func layout(view: View, replace group: ConstraintGroup = ConstraintGroup( /// /// The views will have their layout updated after this call. /// -/// :param: view1 A view to layout. -/// :param: view2 A view to layout. -/// :param: replace The `ConstraintGroup` whose constraints should be replaced. -/// :param: block A block that declares the layout for the views. +/// - parameter view1: A view to layout. +/// - parameter view2: A view to layout. +/// - parameter replace: The `ConstraintGroup` whose constraints should be replaced. +/// - parameter block: A block that declares the layout for the views. /// -public func layout(view1: View, view2: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: (LayoutProxy, LayoutProxy) -> ()) -> ConstraintGroup { +public func layout(_ view1: View, _ view2: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: (LayoutProxy, LayoutProxy) -> ()) -> ConstraintGroup { let context = Context() block(LayoutProxy(context, view1), LayoutProxy(context, view2)) group.replaceConstraints(context.constraints, performLayout: true) @@ -45,13 +45,13 @@ public func layout(view1: View, view2: View, replace group: ConstraintGroup = Co /// /// The views will have their layout updated after this call. /// -/// :param: view1 A view to layout. -/// :param: view2 A view to layout. -/// :param: view3 A view to layout. -/// :param: replace The `ConstraintGroup` whose constraints should be replaced. -/// :param: block A block that declares the layout for the views. +/// - parameter view1: A view to layout. +/// - parameter view2: A view to layout. +/// - parameter view3: A view to layout. +/// - parameter replace: The `ConstraintGroup` whose constraints should be replaced. +/// - parameter block: A block that declares the layout for the views. /// -public func layout(view1: View, view2: View, view3: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: (LayoutProxy, LayoutProxy, LayoutProxy) -> ()) -> ConstraintGroup { +public func layout(_ view1: View, _ view2: View, _ view3: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: (LayoutProxy, LayoutProxy, LayoutProxy) -> ()) -> ConstraintGroup { let context = Context() block(LayoutProxy(context, view1), LayoutProxy(context, view2), LayoutProxy(context, view3)) group.replaceConstraints(context.constraints, performLayout: true) @@ -63,9 +63,9 @@ public func layout(view1: View, view2: View, view3: View, replace group: Constra /// /// The views will have their layout updated after this call. /// -/// :param: views The views to layout. -/// :param: replace The `ConstraintGroup` whose constraints should be replaced. -/// :param: block A block that declares the layout for `views`. +/// - parameter views: The views to layout. +/// - parameter replace: The `ConstraintGroup` whose constraints should be replaced. +/// - parameter block: A block that declares the layout for `views`. /// public func layout(views: [View], replace group: ConstraintGroup = ConstraintGroup(), @noescape block: ([LayoutProxy]) -> ()) -> ConstraintGroup { let context = Context() @@ -79,13 +79,13 @@ public func layout(views: [View], replace group: ConstraintGroup = ConstraintGro /// /// The views will have their layout updated after this call. /// -/// :param: views The views to layout. -/// :param: replace The `ConstraintGroup` whose constraints should be replaced. -/// :param: block A block that declares the layout for `views`. +/// - parameter views: The views to layout. +/// - parameter replace: The `ConstraintGroup` whose constraints should be replaced. +/// - parameter block: A block that declares the layout for `views`. /// public func layout(views: [T: View], replace group: ConstraintGroup = ConstraintGroup(), @noescape block: ([T : LayoutProxy] -> ())) -> ConstraintGroup { let context = Context() - let proxies = map(views) { ($0, LayoutProxy(context, $1)) } + let proxies = views.map { ($0, LayoutProxy(context, $1)) } block(Dictionary(proxies)) group.replaceConstraints(context.constraints, performLayout: true) @@ -96,7 +96,7 @@ public func layout(views: [T: View], replace group: ConstraintGroup /// /// The affected views will have their layout updated after this call. /// -/// :param: clear The `ConstraintGroup` whose constraints should be removed. +/// - parameter clear: The `ConstraintGroup` whose constraints should be removed. /// public func layout(clear group: ConstraintGroup) { group.replaceConstraints([], performLayout: true) @@ -104,11 +104,11 @@ public func layout(clear group: ConstraintGroup) { /// Updates the constraints of a single view. /// -/// :param: view The view to layout. -/// :param: replace The `ConstraintGroup` whose constraints should be replaced. -/// :param: block A block that declares the layout for `view`. +/// - parameter view: The view to layout. +/// - parameter replace: The `ConstraintGroup` whose constraints should be replaced. +/// - parameter block: A block that declares the layout for `view`. /// -public func constrain(view: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: LayoutProxy -> ()) -> ConstraintGroup { +public func constrain(_ view: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: LayoutProxy -> ()) -> ConstraintGroup { let context = Context() block(LayoutProxy(context, view)) group.replaceConstraints(context.constraints, performLayout: false) @@ -118,12 +118,12 @@ public func constrain(view: View, replace group: ConstraintGroup = ConstraintGro /// Updates the constraints of two views. /// -/// :param: view1 A view to layout. -/// :param: view2 A view to layout. -/// :param: replace The `ConstraintGroup` whose constraints should be replaced. -/// :param: block A block that declares the layout for the views. +/// - parameter view1: A view to layout. +/// - parameter view2: A view to layout. +/// - parameter replace: The `ConstraintGroup` whose constraints should be replaced. +/// - parameter block: A block that declares the layout for the views. /// -public func constrain(v1: View, v2: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: (LayoutProxy, LayoutProxy) -> ()) -> ConstraintGroup { +public func constrain(_ v1: View, _ v2: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: (LayoutProxy, LayoutProxy) -> ()) -> ConstraintGroup { let context = Context() block(LayoutProxy(context, v1), LayoutProxy(context, v2)) group.replaceConstraints(context.constraints, performLayout: false) @@ -133,13 +133,13 @@ public func constrain(v1: View, v2: View, replace group: ConstraintGroup = Const /// Updates the constraints of three views. /// -/// :param: view1 A view to layout. -/// :param: view2 A view to layout. -/// :param: view3 A view to layout. -/// :param: replace The `ConstraintGroup` whose constraints should be replaced. -/// :param: block A block that declares the layout for the views. +/// - parameter view1: A view to layout. +/// - parameter view2: A view to layout. +/// - parameter view3: A view to layout. +/// - parameter replace: The `ConstraintGroup` whose constraints should be replaced. +/// - parameter block: A block that declares the layout for the views. /// -public func constrain(v1: View, v2: View, v3: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: (LayoutProxy, LayoutProxy, LayoutProxy) -> ()) -> ConstraintGroup { +public func constrain(_ v1: View, _ v2: View, _ v3: View, replace group: ConstraintGroup = ConstraintGroup(), @noescape block: (LayoutProxy, LayoutProxy, LayoutProxy) -> ()) -> ConstraintGroup { let context = Context() block(LayoutProxy(context, v1), LayoutProxy(context, v2), LayoutProxy(context, v3)) group.replaceConstraints(context.constraints, performLayout: false) @@ -149,9 +149,9 @@ public func constrain(v1: View, v2: View, v3: View, replace group: ConstraintGro /// Updates the constraints of an array of views. /// -/// :param: views The views to layout. -/// :param: replace The `ConstraintGroup` whose constraints should be replaced. -/// :param: block A block that declares the layout for `views`. +/// - parameter views: The views to layout. +/// - parameter replace: The `ConstraintGroup` whose constraints should be replaced. +/// - parameter block: A block that declares the layout for `views`. /// public func constrain(views: [View], replace group: ConstraintGroup = ConstraintGroup(), @noescape block: ([LayoutProxy]) -> ()) -> ConstraintGroup { let context = Context() @@ -163,13 +163,13 @@ public func constrain(views: [View], replace group: ConstraintGroup = Constraint /// Updates the constraints of a dictionary of views. /// -/// :param: views The views to layout. -/// :param: replace The `ConstraintGroup` whose constraints should be replaced. -/// :param: block A block that declares the layout for `views`. +/// - parameter views: The views to layout. +/// - parameter replace: The `ConstraintGroup` whose constraints should be replaced. +/// - parameter block: A block that declares the layout for `views`. /// public func constrain(views: [T: View], replace group: ConstraintGroup = ConstraintGroup(), @noescape block: ([T : LayoutProxy] -> ())) -> ConstraintGroup { let context = Context() - let proxies = map(views) { ($0, LayoutProxy(context, $1)) } + let proxies = views.map { ($0, LayoutProxy(context, $1)) } block(Dictionary(proxies)) group.replaceConstraints(context.constraints, performLayout: false) @@ -178,7 +178,7 @@ public func constrain(views: [T: View], replace group: ConstraintGr /// Removes all constraints for a group. /// -/// :param: clear The `ConstraintGroup` whose constraints should be removed. +/// - parameter clear: The `ConstraintGroup` whose constraints should be removed. /// public func constrain(clear group: ConstraintGroup) { group.replaceConstraints([], performLayout: false) diff --git a/Cartography/Priority.swift b/Cartography/Priority.swift index 8ba7117..14a7d25 100644 --- a/Cartography/Priority.swift +++ b/Cartography/Priority.swift @@ -20,10 +20,10 @@ infix operator ~ { } /// Sets the priority for a constraint. /// -/// :param: lhs The constraint to update. -/// :param: rhs The new priority. +/// - parameter lhs: The constraint to update. +/// - parameter rhs: The new priority. /// -/// :returns: The same constraint with its priority updated. +/// - returns: The same constraint with its priority updated. /// public func ~ (lhs: NSLayoutConstraint, rhs: LayoutPriority) -> NSLayoutConstraint { lhs.priority = rhs @@ -33,10 +33,10 @@ public func ~ (lhs: NSLayoutConstraint, rhs: LayoutPriority) -> NSLayoutConstrai /// Sets the priority for multiple constraints. /// -/// :param: lhs An array of `NSLayoutConstraint` instances. -/// :param: rhs The new priority. +/// - parameter lhs: An array of `NSLayoutConstraint` instances. +/// - parameter rhs: The new priority. /// -/// :returns: The same constraints with their priorities updated. +/// - returns: The same constraints with their priorities updated. /// public func ~ (lhs: [NSLayoutConstraint], rhs: LayoutPriority) -> [NSLayoutConstraint] { return lhs.map { diff --git a/Cartography/Property.swift b/Cartography/Property.swift index 2c13ed1..dda5be7 100644 --- a/Cartography/Property.swift +++ b/Cartography/Property.swift @@ -26,11 +26,11 @@ public protocol NumericalEquality : Property { } /// Declares a property equal to a numerical constant. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The numerical constant. +/// - parameter rhs: The numerical constant. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func == (lhs: NumericalEquality, rhs: CGFloat) -> NSLayoutConstraint { return lhs.context.addConstraint(lhs, coefficients: Coefficients(1, rhs)) @@ -42,11 +42,11 @@ public protocol RelativeEquality : Property { } /// Declares a property equal to a the result of an expression. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The expression. +/// - parameter rhs: The expression. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func == (lhs: P, rhs: Expression

) -> NSLayoutConstraint { return lhs.context.addConstraint(lhs, coefficients: rhs.coefficients[0], to: rhs.value) @@ -54,9 +54,9 @@ public func == (lhs: P, rhs: Expression

) -> NSLayoutCons /// Declares a property equal to another property. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The other property. +/// - parameter rhs: The other property. /// public func == (lhs: P, rhs: P) -> NSLayoutConstraint { return lhs.context.addConstraint(lhs, to: rhs) @@ -70,11 +70,11 @@ public protocol NumericalInequality : Property { } /// Declares a property less than or equal to a numerical constant. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The numerical constant. +/// - parameter rhs: The numerical constant. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func <= (lhs: NumericalInequality, rhs: CGFloat) -> NSLayoutConstraint { return lhs.context.addConstraint(lhs, coefficients: Coefficients(1, rhs), relation: NSLayoutRelation.LessThanOrEqual) @@ -82,11 +82,11 @@ public func <= (lhs: NumericalInequality, rhs: CGFloat) -> NSLayoutConstraint { /// Declares a property greater than or equal to a numerical constant. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The numerical constant. +/// - parameter rhs: The numerical constant. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func >= (lhs: NumericalInequality, rhs: CGFloat) -> NSLayoutConstraint { return lhs.context.addConstraint(lhs, coefficients: Coefficients(1, rhs), relation: NSLayoutRelation.GreaterThanOrEqual) @@ -98,11 +98,11 @@ public protocol RelativeInequality : Property { } /// Declares a property less than or equal to another property. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The other property. +/// - parameter rhs: The other property. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func <= (lhs: P, rhs: P) -> NSLayoutConstraint { return lhs.context.addConstraint(lhs, to: rhs, relation: NSLayoutRelation.LessThanOrEqual) @@ -110,11 +110,11 @@ public func <= (lhs: P, rhs: P) -> NSLayoutConstraint { /// Declares a property greater than or equal to another property. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The other property. +/// - parameter rhs: The other property. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func >= (lhs: P, rhs: P) -> NSLayoutConstraint { return lhs.context.addConstraint(lhs, to: rhs, relation: NSLayoutRelation.GreaterThanOrEqual) @@ -122,11 +122,11 @@ public func >= (lhs: P, rhs: P) -> NSLayoutConstraint { /// Declares a property less than or equal to the result of an expression. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The other property. +/// - parameter rhs: The other property. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func <= (lhs: P, rhs: Expression

) -> NSLayoutConstraint { return lhs.context.addConstraint(lhs, coefficients: rhs.coefficients[0], to: rhs.value, relation: NSLayoutRelation.LessThanOrEqual) @@ -134,11 +134,11 @@ public func <= (lhs: P, rhs: Expression

) -> NSLayoutCo /// Declares a property greater than or equal to the result of an expression. /// -/// :param: lhs The affected property. The associated view will have +/// - parameter lhs: The affected property. The associated view will have /// `translatesAutoresizingMaskIntoConstraints` set to `false`. -/// :param: rhs The other property. +/// - parameter rhs: The other property. /// -/// :returns: An `NSLayoutConstraint`. +/// - returns: An `NSLayoutConstraint`. /// public func >= (lhs: P, rhs: Expression

) -> NSLayoutConstraint { return lhs.context.addConstraint(lhs, coefficients: rhs.coefficients[0], to: rhs.value, relation: NSLayoutRelation.GreaterThanOrEqual) diff --git a/Cartography/View.swift b/Cartography/View.swift index 60358f0..ac5676e 100644 --- a/Cartography/View.swift +++ b/Cartography/View.swift @@ -18,8 +18,8 @@ import Foundation } public var car_translatesAutoresizingMaskIntoConstraints: Bool { - get { return translatesAutoresizingMaskIntoConstraints() } - set { setTranslatesAutoresizingMaskIntoConstraints(newValue) } + get { return translatesAutoresizingMaskIntoConstraints } + set { translatesAutoresizingMaskIntoConstraints = newValue } } } #else diff --git a/Cartography/ViewUtils.swift b/Cartography/ViewUtils.swift index 970ad91..3f8c3de 100644 --- a/Cartography/ViewUtils.swift +++ b/Cartography/ViewUtils.swift @@ -23,7 +23,7 @@ internal func closestCommonAncestor(a: View, b: View) -> View? { if aSuper === bSuper { return aSuper } - var ancestorsOfA = Set(ancestors(a)) + let ancestorsOfA = Set(ancestors(a)) for ancestor in ancestors(b) { if ancestorsOfA.contains(ancestor) { @@ -34,10 +34,10 @@ internal func closestCommonAncestor(a: View, b: View) -> View? { return .None } -private func ancestors(v: View) -> SequenceOf { - return SequenceOf { () -> GeneratorOf in +private func ancestors(v: View) -> AnySequence { + return AnySequence { () -> AnyGenerator in var view: View? = v - return GeneratorOf { + return anyGenerator { let current = view view = view?.superview return current diff --git a/CartographyTests/Info.plist b/CartographyTests/Info.plist index 1ed710d..6d32c15 100644 --- a/CartographyTests/Info.plist +++ b/CartographyTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.robertboehnke.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/CartographyTests/TestView.swift b/CartographyTests/TestView.swift index e6738f9..bdb1561 100644 --- a/CartographyTests/TestView.swift +++ b/CartographyTests/TestView.swift @@ -13,7 +13,7 @@ class TestView: View { super.init(frame: frame) #if os(iOS) - setTranslatesAutoresizingMaskIntoConstraints(false) + translatesAutoresizingMaskIntoConstraints = false #else translatesAutoresizingMaskIntoConstraints = false #endif @@ -25,7 +25,7 @@ class TestView: View { #if os(iOS) var car_constraints: [NSLayoutConstraint] { - return constraints() as! [NSLayoutConstraint] + return constraints } #else var car_constraints: [NSLayoutConstraint] { diff --git a/CartographyTests/ViewHierarchySpec.swift b/CartographyTests/ViewHierarchySpec.swift index 58a3e02..4897d4c 100644 --- a/CartographyTests/ViewHierarchySpec.swift +++ b/CartographyTests/ViewHierarchySpec.swift @@ -9,8 +9,8 @@ class ViewHierarchySpec: QuickSpec { pending("should throw an exception if the views share no common ancestor") { let viewA = TestView() let viewB = TestView() - - expect({ + + expect(expression: { layout(viewA, viewB) { viewA, viewB in viewA.width == viewB.width }