Переглянути джерело

Merge pull request #251 from pawlowskialex/feature/0.40.0

Migration to the latest Swift 3.0 syntax and macOS Cocoa API
Robert Payne 9 роки тому
батько
коміт
47d84e1e62

+ 9 - 1
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;
 		};

+ 5 - 5
SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme

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

+ 5 - 5
SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme

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

+ 1 - 1
SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit tvOS.xcscheme

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

+ 1 - 1
Source/Constraint.swift

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

+ 14 - 14
Source/ConstraintConstantTarget.swift

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

+ 1 - 1
Source/ConstraintInsets.swift

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

+ 6 - 6
Source/ConstraintMaker.swift

@@ -135,7 +135,7 @@ public class ConstraintMaker {
         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)
         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)
         }
     }
     

+ 4 - 0
Source/ConstraintMakerEditable.swift

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

+ 5 - 0
Source/ConstraintMakerPriortizable.swift

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

+ 3 - 0
Source/ConstraintMakerRelatable.swift

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

+ 8 - 8
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.")

+ 4 - 4
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)
     }
     

+ 27 - 16
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<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 {
     let pointerDescription = NSString(format: "%p", UInt(ObjectIdentifier(object)))
     var desc = ""