diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index e22c0fe..b6c1f92 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -490,7 +490,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "SnapKit Team"; TargetAttributes = { 537DCE911C35CC8800B5B899 = { @@ -771,6 +771,7 @@ PRODUCT_NAME = SnapKit; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; @@ -804,6 +805,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TVOS_DEPLOYMENT_TARGET = 9.1; }; name = Release; @@ -831,6 +833,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -875,6 +878,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -931,6 +935,7 @@ PRODUCT_NAME = SnapKit; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -957,6 +962,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; }; name = Release; @@ -1012,6 +1018,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1044,6 +1051,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; }; name = Release; }; diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme index 3ffad95..15b42fe 100644 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -66,11 +66,11 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -66,11 +66,11 @@ Void) -> [Constraint] { + internal static func prepareConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) -> [Constraint] { let maker = ConstraintMaker(view: view) closure(make: maker) let constraints = maker.descriptions @@ -145,7 +145,7 @@ public class ConstraintMaker { 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) closure(make: maker) let constraints = maker.descriptions @@ -153,16 +153,16 @@ public class ConstraintMaker { .filter { $0 != nil } .map { $0! } 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.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) closure(make: maker) let constraints = maker.descriptions @@ -170,7 +170,7 @@ public class ConstraintMaker { .filter { $0 != nil } .map { $0! } for constraint in constraints { - constraint.installIfNeeded(updateExisting: true) + let _ = constraint.installIfNeeded(updateExisting: true) } } diff --git a/Source/ConstraintView+Extensions.swift b/Source/ConstraintView+Extensions.swift index a371448..cd08dd0 100644 --- a/Source/ConstraintView+Extensions.swift +++ b/Source/ConstraintView+Extensions.swift @@ -106,23 +106,23 @@ public extension ConstraintView { public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins } @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") - public func snp_prepareConstraints(@noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { - return self.snp.prepareConstraints(closure: closure) + public func snp_prepareConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) -> [Constraint] { + return self.snp.prepareConstraints(closure) } @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") - public func snp_makeConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { - self.snp.makeConstraints(closure: closure) + public func snp_makeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { + self.snp.makeConstraints(closure) } @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") - public func snp_remakeConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { - self.snp.remakeConstraints(closure: closure) + public func snp_remakeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { + self.snp.remakeConstraints(closure) } @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") - public func snp_updateConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { - self.snp.updateConstraints(closure: closure) + public func snp_updateConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { + self.snp.updateConstraints(closure) } @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index 31b9174..3e85df0 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -141,19 +141,19 @@ public struct ConstraintViewDSL { 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) } - public func makeConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { + public func makeConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) { 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) } - public func updateConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { + public func updateConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) { ConstraintMaker.updateConstraints(view: self.view, closure: closure) } diff --git a/Source/Debugging.swift b/Source/Debugging.swift index c3caae8..e4bec9f 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -34,14 +34,17 @@ public extension LayoutConstraint { description += descriptionForObject(self) - description += " \(descriptionForObject(self.firstItem))" + if let firstItem = conditionalOptional(from: self.firstItem) { + description += " \(descriptionForObject(firstItem))" + } + if self.firstAttribute != .notAnAttribute { description += ".\(descriptionForAttribute(self.firstAttribute))" } description += " \(descriptionForRelation(self.relation))" - if let secondItem: AnyObject = self.secondItem { + if let secondItem = self.secondItem { description += " \(descriptionForObject(secondItem))" } @@ -96,7 +99,7 @@ private func descriptionForAttribute(_ attribute: NSLayoutAttribute) -> String { case .height: return "height" case .centerX: return "centerX" case .centerY: return "centerY" - case .lastBaseline: return "baseline" + case .lastBaseline: return "lastBaseline" case .firstBaseline: return "firstBaseline" case .topMargin: return "topMargin" case .leftMargin: return "leftMargin" @@ -109,23 +112,31 @@ private func descriptionForAttribute(_ attribute: NSLayoutAttribute) -> String { } #else switch attribute { - case .NotAnAttribute: return "notAnAttribute" - case .Top: return "top" - case .Left: return "left" - case .Bottom: return "bottom" - case .Right: return "right" - case .Leading: return "leading" - case .Trailing: return "trailing" - case .Width: return "width" - case .Height: return "height" - case .CenterX: return "centerX" - case .CenterY: return "centerY" - case .Baseline: return "baseline" - default: return "default" + case .notAnAttribute: return "notAnAttribute" + case .top: return "top" + case .left: return "left" + case .bottom: return "bottom" + case .right: return "right" + case .leading: return "leading" + case .trailing: return "trailing" + case .width: return "width" + case .height: return "height" + case .centerX: return "centerX" + case .centerY: return "centerY" + case .lastBaseline: return "lastBaseline" + case .firstBaseline: return "firstBaseline" } #endif } +private func conditionalOptional(from object: Optional) -> Optional { + return object +} + +private func conditionalOptional(from object: T) -> Optional { + return Optional.some(object) +} + private func descriptionForObject(_ object: AnyObject) -> String { let pointerDescription = NSString(format: "%p", UInt(ObjectIdentifier(object))) var desc = ""