From 9cfdae4d8f361bcfebc7bdc9f08a9aad2dc38ad2 Mon Sep 17 00:00:00 2001 From: Piet Brauer Date: Tue, 20 Sep 2016 17:20:38 +0200 Subject: [PATCH] Update to Swift 3.0 --- JSDiff.xcodeproj/project.pbxproj | 17 +++++++++++++- .../xcschemes/JSDiff-tvOS.xcscheme | 2 +- .../xcshareddata/xcschemes/JSDiff.xcscheme | 2 +- JSDiff/JSDiff.swift | 22 +++++++++---------- JSDiffTests/JSDiffTests.swift | 10 ++++----- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/JSDiff.xcodeproj/project.pbxproj b/JSDiff.xcodeproj/project.pbxproj index 16be453..827fbb1 100644 --- a/JSDiff.xcodeproj/project.pbxproj +++ b/JSDiff.xcodeproj/project.pbxproj @@ -248,7 +248,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "nerdish by nature"; TargetAttributes = { 2380771E1CB94D9600415155 = { @@ -259,9 +259,11 @@ }; 23A4A1531CB93D6500A3DEE3 = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; 23A4A15D1CB93D6500A3DEE3 = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; }; }; @@ -407,6 +409,7 @@ 238077311CB94D9700415155 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -423,6 +426,7 @@ 238077321CB94D9700415155 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -474,8 +478,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -506,6 +512,7 @@ PRODUCT_NAME = JSDiff; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -526,8 +533,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -550,6 +559,8 @@ PRODUCT_BUNDLE_IDENTIFIER = com.nerdishbynature.JSDiff; PRODUCT_NAME = JSDiff; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -561,6 +572,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -576,6 +588,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -595,6 +608,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.nerdishbynature.JSDiffTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -606,6 +620,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.nerdishbynature.JSDiffTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/JSDiff.xcodeproj/xcshareddata/xcschemes/JSDiff-tvOS.xcscheme b/JSDiff.xcodeproj/xcshareddata/xcschemes/JSDiff-tvOS.xcscheme index bea4f81..0d8f128 100644 --- a/JSDiff.xcodeproj/xcshareddata/xcschemes/JSDiff-tvOS.xcscheme +++ b/JSDiff.xcodeproj/xcshareddata/xcschemes/JSDiff-tvOS.xcscheme @@ -1,6 +1,6 @@ [[String: AnyObject]] { + fileprivate func results(_ oldLine: String, newLine: String) -> [[String: AnyObject]] { let diff = context.objectForKeyedSubscript("swift_diffStrings") - return diff.callWithArguments([oldLine, newLine]).toArray() as? [[String: AnyObject]] ?? [] + return diff!.call(withArguments: [oldLine, newLine]).toArray() as? [[String: AnyObject]] ?? [] } - @objc public func diffWords(oldLine: String, newLine: String) -> JSLineDiff { + @objc open func diffWords(_ oldLine: String, newLine: String) -> JSLineDiff { var oldLineIndex = 0 var newLineIndex = 0 let attributedOldLine = NSMutableAttributedString(string: oldLine) diff --git a/JSDiffTests/JSDiffTests.swift b/JSDiffTests/JSDiffTests.swift index fedb307..2999bdf 100644 --- a/JSDiffTests/JSDiffTests.swift +++ b/JSDiffTests/JSDiffTests.swift @@ -16,13 +16,13 @@ class JSDiffTests: XCTestCase { let jsDiff = JSDiff(deletedColor: UIColor.deletedColor(), deletedWordColor: UIColor.strongDeletedColor(), addedColor: UIColor.addedColor(), addedWordColor: UIColor.strongAddedColor()) let expectedOldLine = NSMutableAttributedString(string: oldLine, attributes: [NSBackgroundColorAttributeName: UIColor.deletedColor()]) - expectedOldLine.addAttributes([NSBackgroundColorAttributeName: UIColor.strongDeletedColor()], range: (oldLine as NSString).rangeOfString("-you-always")) - expectedOldLine.addAttributes([NSBackgroundColorAttributeName: UIColor.strongDeletedColor()], range: (oldLine as NSString).rangeOfString("id963577401")) + expectedOldLine.addAttributes([NSBackgroundColorAttributeName: UIColor.strongDeletedColor()], range: (oldLine as NSString).range(of: "-you-always")) + expectedOldLine.addAttributes([NSBackgroundColorAttributeName: UIColor.strongDeletedColor()], range: (oldLine as NSString).range(of: "id963577401")) let expectedNewLine = NSMutableAttributedString(string: newLine, attributes: [NSBackgroundColorAttributeName: UIColor.addedColor()]) - expectedNewLine.addAttributes([NSBackgroundColorAttributeName: UIColor.strongAddedColor()], range: (newLine as NSString).rangeOfString("enterprise-")) - expectedNewLine.addAttributes([NSBackgroundColorAttributeName: UIColor.strongAddedColor()], range: (newLine as NSString).rangeOfString("id1079716387")) - expectedNewLine.addAttributes([NSBackgroundColorAttributeName: UIColor.strongAddedColor()], range: (newLine as NSString).rangeOfString("ls=1&")) + expectedNewLine.addAttributes([NSBackgroundColorAttributeName: UIColor.strongAddedColor()], range: (newLine as NSString).range(of: "enterprise-")) + expectedNewLine.addAttributes([NSBackgroundColorAttributeName: UIColor.strongAddedColor()], range: (newLine as NSString).range(of: "id1079716387")) + expectedNewLine.addAttributes([NSBackgroundColorAttributeName: UIColor.strongAddedColor()], range: (newLine as NSString).range(of: "ls=1&")) let result = jsDiff.diffWords(oldLine, newLine: newLine) XCTAssertEqual(result.oldLine, expectedOldLine)