Merge pull request #251 from pawlowskialex/feature/0.40.0

Migration to the latest Swift 3.0 syntax and macOS Cocoa API
This commit is contained in:
Robert Payne 2016-07-07 04:04:49 +12:00 committed by GitHub
commit 47d84e1e62
14 changed files with 93 additions and 62 deletions

View File

@ -490,7 +490,7 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 0720; LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0700; LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "SnapKit Team"; ORGANIZATIONNAME = "SnapKit Team";
TargetAttributes = { TargetAttributes = {
537DCE911C35CC8800B5B899 = { 537DCE911C35CC8800B5B899 = {
@ -771,6 +771,7 @@
PRODUCT_NAME = SnapKit; PRODUCT_NAME = SnapKit;
SDKROOT = appletvos; SDKROOT = appletvos;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0; SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3; TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0; TVOS_DEPLOYMENT_TARGET = 9.0;
@ -804,6 +805,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos; SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TVOS_DEPLOYMENT_TARGET = 9.1; TVOS_DEPLOYMENT_TARGET = 9.1;
}; };
name = Release; name = Release;
@ -831,6 +833,7 @@
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = ( GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1", "DEBUG=1",
@ -875,6 +878,7 @@
ENABLE_NS_ASSERTIONS = NO; ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNDECLARED_SELECTOR = YES;
@ -931,6 +935,7 @@
PRODUCT_NAME = SnapKit; PRODUCT_NAME = SnapKit;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0; SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = ""; VERSION_INFO_PREFIX = "";
@ -957,6 +962,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0; SWIFT_VERSION = 3.0;
}; };
name = Release; name = Release;
@ -1012,6 +1018,7 @@
SDKROOT = macosx; SDKROOT = macosx;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = macosx; SUPPORTED_PLATFORMS = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = ""; VERSION_INFO_PREFIX = "";
}; };
@ -1044,6 +1051,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
}; };
name = Release; name = Release;
}; };

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0700" LastUpgradeVersion = "0800"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
@ -37,10 +37,10 @@
</BuildActionEntries> </BuildActionEntries>
</BuildAction> </BuildAction>
<TestAction <TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES">
buildConfiguration = "Debug">
<Testables> <Testables>
<TestableReference <TestableReference
skipped = "NO"> skipped = "NO">
@ -66,11 +66,11 @@
</AdditionalOptions> </AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES" debugDocumentVersioning = "YES"
debugServiceExtension = "internal" debugServiceExtension = "internal"
@ -88,10 +88,10 @@
</AdditionalOptions> </AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = "" savedToolIdentifier = ""
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES"> debugDocumentVersioning = "YES">
<MacroExpansion> <MacroExpansion>
<BuildableReference <BuildableReference

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0700" LastUpgradeVersion = "0800"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
@ -37,10 +37,10 @@
</BuildActionEntries> </BuildActionEntries>
</BuildAction> </BuildAction>
<TestAction <TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES">
buildConfiguration = "Debug">
<Testables> <Testables>
<TestableReference <TestableReference
skipped = "NO"> skipped = "NO">
@ -66,11 +66,11 @@
</AdditionalOptions> </AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES" debugDocumentVersioning = "YES"
debugServiceExtension = "internal" debugServiceExtension = "internal"
@ -88,10 +88,10 @@
</AdditionalOptions> </AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = "" savedToolIdentifier = ""
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES"> debugDocumentVersioning = "YES">
<MacroExpansion> <MacroExpansion>
<BuildableReference <BuildableReference

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0720" LastUpgradeVersion = "0800"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"

View File

@ -240,7 +240,7 @@ public class Constraint {
internal func activateIfNeeded() { internal func activateIfNeeded() {
guard self.installInfo != nil else { guard self.installInfo != nil else {
self.installIfNeeded() let _ = self.installIfNeeded()
return return
} }
#if SNAPKIT_DEPLOYMENT_LEGACY #if SNAPKIT_DEPLOYMENT_LEGACY

View File

@ -86,11 +86,11 @@ extension ConstraintConstantTarget {
} }
#else #else
switch layoutAttribute { switch layoutAttribute {
case .Left, .Right, .Leading, .Trailing, .CenterX: case .left, .right, .leading, .trailing, .centerX:
return value.x return value.x
case .Top, .Bottom, .CenterY, .Baseline, .FirstBaseline: case .top, .bottom, .centerY, .lastBaseline, .firstBaseline:
return value.y return value.y
case .Width, .Height, .NotAnAttribute: case .width, .height, .notAnAttribute:
return 0.0 return 0.0
} }
#endif #endif
@ -120,23 +120,23 @@ extension ConstraintConstantTarget {
} }
#else #else
switch layoutAttribute { switch layoutAttribute {
case .Left, .CenterX: case .left, .centerX:
return value.left return value.left
case .Top, .CenterY, .Baseline, .FirstBaseline: case .top, .centerY, .lastBaseline, .firstBaseline:
return value.top return value.top
case .Right: case .right:
return value.right return value.right
case .Bottom: case .bottom:
return value.bottom return value.bottom
case .Leading: case .leading:
return (ConstraintConfig.interfaceLayoutDirection == .LeftToRight) ? value.left : -value.right return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : -value.right
case .Trailing: case .trailing:
return (ConstraintConfig.interfaceLayoutDirection == .LeftToRight) ? value.right : -value.left return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.right : -value.left
case .Width: case .width:
return -value.left + value.right return -value.left + value.right
case .Height: case .height:
return -value.top + value.bottom return -value.top + value.bottom
case .NotAnAttribute: case .notAnAttribute:
return 0.0 return 0.0
} }
#endif #endif

View File

@ -31,5 +31,5 @@
#if os(iOS) || os(tvOS) #if os(iOS) || os(tvOS)
public typealias ConstraintInsets = UIEdgeInsets public typealias ConstraintInsets = UIEdgeInsets
#else #else
public typealias ConstraintInsets = NSEdgeInsets public typealias ConstraintInsets = EdgeInsets
#endif #endif

View File

@ -135,7 +135,7 @@ public class ConstraintMaker {
return ConstraintMakerExtendable(description) return ConstraintMakerExtendable(description)
} }
internal static func prepareConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { internal static func prepareConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) -> [Constraint] {
let maker = ConstraintMaker(view: view) let maker = ConstraintMaker(view: view)
closure(make: maker) closure(make: maker)
let constraints = maker.descriptions let constraints = maker.descriptions
@ -145,7 +145,7 @@ public class ConstraintMaker {
return constraints return constraints
} }
internal static func makeConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { internal static func makeConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) {
let maker = ConstraintMaker(view: view) let maker = ConstraintMaker(view: view)
closure(make: maker) closure(make: maker)
let constraints = maker.descriptions let constraints = maker.descriptions
@ -153,16 +153,16 @@ public class ConstraintMaker {
.filter { $0 != nil } .filter { $0 != nil }
.map { $0! } .map { $0! }
for constraint in constraints { for constraint in constraints {
constraint.installIfNeeded() let _ = constraint.installIfNeeded()
} }
} }
internal static func remakeConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { internal static func remakeConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) {
self.removeConstraints(view: view) self.removeConstraints(view: view)
self.makeConstraints(view: view, closure: closure) self.makeConstraints(view: view, closure: closure)
} }
internal static func updateConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { internal static func updateConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) {
let maker = ConstraintMaker(view: view) let maker = ConstraintMaker(view: view)
closure(make: maker) closure(make: maker)
let constraints = maker.descriptions let constraints = maker.descriptions
@ -170,7 +170,7 @@ public class ConstraintMaker {
.filter { $0 != nil } .filter { $0 != nil }
.map { $0! } .map { $0! }
for constraint in constraints { for constraint in constraints {
constraint.installIfNeeded(updateExisting: true) let _ = constraint.installIfNeeded(updateExisting: true)
} }
} }

View File

@ -30,20 +30,24 @@
public class ConstraintMakerEditable: ConstraintMakerPriortizable { public class ConstraintMakerEditable: ConstraintMakerPriortizable {
@discardableResult
public func multipliedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { public func multipliedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable {
self.description.multiplier = amount self.description.multiplier = amount
return self return self
} }
@discardableResult
public func dividedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { public func dividedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable {
return self.multipliedBy(1.0 / amount.constraintMultiplierTargetValue) return self.multipliedBy(1.0 / amount.constraintMultiplierTargetValue)
} }
@discardableResult
public func offset(_ amount: ConstraintOffsetTarget) -> ConstraintMakerEditable { public func offset(_ amount: ConstraintOffsetTarget) -> ConstraintMakerEditable {
self.description.constant = amount self.description.constant = amount
return self return self
} }
@discardableResult
public func inset(_ amount: ConstraintInsetTarget) -> ConstraintMakerEditable { public func inset(_ amount: ConstraintInsetTarget) -> ConstraintMakerEditable {
let insets: ConstraintInsets let insets: ConstraintInsets

View File

@ -30,19 +30,23 @@
public class ConstraintMakerPriortizable: ConstraintMakerFinalizable { public class ConstraintMakerPriortizable: ConstraintMakerFinalizable {
@discardableResult
public func priority(_ amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable { public func priority(_ amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable {
self.description.priority = amount self.description.priority = amount
return self return self
} }
@discardableResult
public func priorityRequired() -> ConstraintMakerFinalizable { public func priorityRequired() -> ConstraintMakerFinalizable {
return self.priority(1000) return self.priority(1000)
} }
@discardableResult
public func priorityHigh() -> ConstraintMakerFinalizable { public func priorityHigh() -> ConstraintMakerFinalizable {
return self.priority(750) return self.priority(750)
} }
@discardableResult
public func priorityMedium() -> ConstraintMakerFinalizable { public func priorityMedium() -> ConstraintMakerFinalizable {
#if os(iOS) || os(tvOS) #if os(iOS) || os(tvOS)
return self.priority(500) return self.priority(500)
@ -51,6 +55,7 @@ public class ConstraintMakerPriortizable: ConstraintMakerFinalizable {
#endif #endif
} }
@discardableResult
public func priorityLow() -> ConstraintMakerFinalizable { public func priorityLow() -> ConstraintMakerFinalizable {
return self.priority(250) return self.priority(250)
} }

View File

@ -67,14 +67,17 @@ public class ConstraintMakerRelatable {
return editable return editable
} }
@discardableResult
public func equalTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { public func equalTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
return self.relatedTo(other, relation: .equal, file: file, line: line) return self.relatedTo(other, relation: .equal, file: file, line: line)
} }
@discardableResult
public func lessThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { public func lessThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line) return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line)
} }
@discardableResult
public func greaterThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable { public func greaterThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line) return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line)
} }

View File

@ -106,23 +106,23 @@ public extension ConstraintView {
public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins } public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins }
@available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.")
public func snp_prepareConstraints(@noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { public func snp_prepareConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) -> [Constraint] {
return self.snp.prepareConstraints(closure: closure) return self.snp.prepareConstraints(closure)
} }
@available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.")
public func snp_makeConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { public func snp_makeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) {
self.snp.makeConstraints(closure: closure) self.snp.makeConstraints(closure)
} }
@available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.")
public func snp_remakeConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { public func snp_remakeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) {
self.snp.remakeConstraints(closure: closure) self.snp.remakeConstraints(closure)
} }
@available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.")
public func snp_updateConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { public func snp_updateConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) {
self.snp.updateConstraints(closure: closure) self.snp.updateConstraints(closure)
} }
@available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.")

View File

@ -141,19 +141,19 @@ public struct ConstraintViewDSL {
return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterWithinMargins) return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterWithinMargins)
} }
public func prepareConstraints(closure: @noescape (make: ConstraintMaker) -> Void) -> [Constraint] { public func prepareConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) -> [Constraint] {
return ConstraintMaker.prepareConstraints(view: self.view, closure: closure) return ConstraintMaker.prepareConstraints(view: self.view, closure: closure)
} }
public func makeConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { public func makeConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) {
ConstraintMaker.makeConstraints(view: self.view, closure: closure) ConstraintMaker.makeConstraints(view: self.view, closure: closure)
} }
public func remakeConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { public func remakeConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) {
ConstraintMaker.remakeConstraints(view: self.view, closure: closure) ConstraintMaker.remakeConstraints(view: self.view, closure: closure)
} }
public func updateConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { public func updateConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) {
ConstraintMaker.updateConstraints(view: self.view, closure: closure) ConstraintMaker.updateConstraints(view: self.view, closure: closure)
} }

View File

@ -34,14 +34,17 @@ public extension LayoutConstraint {
description += descriptionForObject(self) description += descriptionForObject(self)
description += " \(descriptionForObject(self.firstItem))" if let firstItem = conditionalOptional(from: self.firstItem) {
description += " \(descriptionForObject(firstItem))"
}
if self.firstAttribute != .notAnAttribute { if self.firstAttribute != .notAnAttribute {
description += ".\(descriptionForAttribute(self.firstAttribute))" description += ".\(descriptionForAttribute(self.firstAttribute))"
} }
description += " \(descriptionForRelation(self.relation))" description += " \(descriptionForRelation(self.relation))"
if let secondItem: AnyObject = self.secondItem { if let secondItem = self.secondItem {
description += " \(descriptionForObject(secondItem))" description += " \(descriptionForObject(secondItem))"
} }
@ -96,7 +99,7 @@ private func descriptionForAttribute(_ attribute: NSLayoutAttribute) -> String {
case .height: return "height" case .height: return "height"
case .centerX: return "centerX" case .centerX: return "centerX"
case .centerY: return "centerY" case .centerY: return "centerY"
case .lastBaseline: return "baseline" case .lastBaseline: return "lastBaseline"
case .firstBaseline: return "firstBaseline" case .firstBaseline: return "firstBaseline"
case .topMargin: return "topMargin" case .topMargin: return "topMargin"
case .leftMargin: return "leftMargin" case .leftMargin: return "leftMargin"
@ -109,23 +112,31 @@ private func descriptionForAttribute(_ attribute: NSLayoutAttribute) -> String {
} }
#else #else
switch attribute { switch attribute {
case .NotAnAttribute: return "notAnAttribute" case .notAnAttribute: return "notAnAttribute"
case .Top: return "top" case .top: return "top"
case .Left: return "left" case .left: return "left"
case .Bottom: return "bottom" case .bottom: return "bottom"
case .Right: return "right" case .right: return "right"
case .Leading: return "leading" case .leading: return "leading"
case .Trailing: return "trailing" case .trailing: return "trailing"
case .Width: return "width" case .width: return "width"
case .Height: return "height" case .height: return "height"
case .CenterX: return "centerX" case .centerX: return "centerX"
case .CenterY: return "centerY" case .centerY: return "centerY"
case .Baseline: return "baseline" case .lastBaseline: return "lastBaseline"
default: return "default" case .firstBaseline: return "firstBaseline"
} }
#endif #endif
} }
private func conditionalOptional<T>(from object: Optional<T>) -> Optional<T> {
return object
}
private func conditionalOptional<T>(from object: T) -> Optional<T> {
return Optional.some(object)
}
private func descriptionForObject(_ object: AnyObject) -> String { private func descriptionForObject(_ object: AnyObject) -> String {
let pointerDescription = NSString(format: "%p", UInt(ObjectIdentifier(object))) let pointerDescription = NSString(format: "%p", UInt(ObjectIdentifier(object)))
var desc = "" var desc = ""