From c869f64efcbe8be9d61021b9b68ad80ccec9e1ca Mon Sep 17 00:00:00 2001 From: Mark Hamilton Date: Fri, 22 Jul 2016 22:40:50 -0700 Subject: [PATCH] Minor Swift 3 Conversion --- PolyglotSample.xcodeproj/project.pbxproj | 8 ++++++++ PolyglotSample/AppDelegate.swift | 2 +- PolyglotSample/ViewController.swift | 4 ++-- PolyglotTests/PolyglotTests.swift | 6 +++--- PolyglotTests/StringExtensionTests.swift | 6 +++--- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/PolyglotSample.xcodeproj/project.pbxproj b/PolyglotSample.xcodeproj/project.pbxproj index 0516092..7e35d0b 100644 --- a/PolyglotSample.xcodeproj/project.pbxproj +++ b/PolyglotSample.xcodeproj/project.pbxproj @@ -184,9 +184,13 @@ TargetAttributes = { B60F87431985F1C200ABB94A = { CreatedOnToolsVersion = 6.0; + DevelopmentTeam = 77898Z5KPT; + DevelopmentTeamName = "Mark Hamilton"; + LastSwiftMigration = 0800; }; B60F87551985F1C200ABB94A = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0800; TestTargetID = B60F87431985F1C200ABB94A; }; }; @@ -414,6 +418,7 @@ PRODUCT_NAME = PolyglotSample; SWIFT_OBJC_BRIDGING_HEADER = "PolyglotSample/Polyglot-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -428,6 +433,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = PolyglotSample; SWIFT_OBJC_BRIDGING_HEADER = "PolyglotSample/Polyglot-Bridging-Header.h"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -450,6 +456,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "PolyglotTests/PolyglotTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUNDLE_LOADER)"; }; name = Debug; @@ -468,6 +475,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "PolyglotTests/PolyglotTests-Bridging-Header.h"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUNDLE_LOADER)"; }; name = Release; diff --git a/PolyglotSample/AppDelegate.swift b/PolyglotSample/AppDelegate.swift index 7ef672b..8008e99 100644 --- a/PolyglotSample/AppDelegate.swift +++ b/PolyglotSample/AppDelegate.swift @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { return true } } diff --git a/PolyglotSample/ViewController.swift b/PolyglotSample/ViewController.swift index 3615f59..9a363a5 100644 --- a/PolyglotSample/ViewController.swift +++ b/PolyglotSample/ViewController.swift @@ -41,10 +41,10 @@ class ViewController: UIViewController { @IBOutlet weak var inputTextField: UITextField! @IBOutlet weak var translationLabel: UILabel! - @IBAction func didTapTranslateButton(sender: AnyObject) { + @IBAction func didTapTranslateButton(_ sender: AnyObject) { guard let text = inputTextField.text else { return } - UIApplication.sharedApplication().networkActivityIndicatorVisible = true + UIApplication.shared().isNetworkActivityIndicatorVisible = true translator.translate(text) { translation in if let language = self.translator.fromLanguage?.rawValue { self.translationLabel.text = "Translated from \(language.capitalizedString): \(translation)" diff --git a/PolyglotTests/PolyglotTests.swift b/PolyglotTests/PolyglotTests.swift index b36c9ab..7979f7d 100644 --- a/PolyglotTests/PolyglotTests.swift +++ b/PolyglotTests/PolyglotTests.swift @@ -74,11 +74,11 @@ class PolyglotTests: XCTestCase { } func testTranslate() { - let expectation = expectationWithDescription("translation done") + let expectation = self.expectation(withDescription: "translation done") // Stub POST access token stubRequest("POST", "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13") - .withBody("client_id=myClientId&client_secret=myClientSecret&scope=http://api.microsofttranslator.com&grant_type=client_credentials".dataUsingEncoding(NSUTF8StringEncoding)) + .withBody("client_id=myClientId&client_secret=myClientSecret&scope=http://api.microsofttranslator.com&grant_type=client_credentials".dataUsingEncoding(String.Encoding.utf8)) .andReturn(200) .withHeaders(["Content-Type": "application/json"]) .withBody("{\"access_token\":\"octocatsruleeverythingaroundme\", \"expires_in\":\"600\"}") @@ -95,6 +95,6 @@ class PolyglotTests: XCTestCase { expectation.fulfill() } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectations(withTimeout: 1, handler: nil) } } diff --git a/PolyglotTests/StringExtensionTests.swift b/PolyglotTests/StringExtensionTests.swift index 3616a46..1fc23f5 100644 --- a/PolyglotTests/StringExtensionTests.swift +++ b/PolyglotTests/StringExtensionTests.swift @@ -39,14 +39,14 @@ class StringExtensionTests: XCTestCase { XCTAssertNil("".language?.rawValue, "Empty strings should return nil.") } - func AssertEqualOptional(@autoclosure optional: () -> T?, @autoclosure _ expected: () -> T, file: String = __FILE__, line: UInt = __LINE__) { + func AssertEqualOptional(@autoclosure _ optional: () -> T?, @autoclosure _ expected: () -> T, file: String = #file, line: UInt = #line) { if let nonOptional = optional() { if nonOptional != expected() { - self.recordFailureWithDescription("Optional (\(nonOptional)) is not equal to (\(expected()))", inFile: file, atLine: line, expected: true) + self.recordFailure(withDescription: "Optional (\(nonOptional)) is not equal to (\(expected()))", inFile: file, atLine: line, expected: true) } } else { - self.recordFailureWithDescription("Optional value is empty", inFile: file, atLine: line, expected: true) + self.recordFailure(withDescription: "Optional value is empty", inFile: file, atLine: line, expected: true) } }