From 9ba4f5ae37a4138450fe9c0e3b177c8a9be7dca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sat, 30 Apr 2016 14:07:04 +0200 Subject: [PATCH 1/2] Revert "Revert comment to main thread call" This reverts commit 3ce889dbc776804554f530291a22055cd70ccb5c. --- Polyglot/Polyglot.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Polyglot/Polyglot.swift b/Polyglot/Polyglot.swift index 159f1a1..cacac6b 100644 --- a/Polyglot/Polyglot.swift +++ b/Polyglot/Polyglot.swift @@ -138,7 +138,8 @@ public class Polyglot { } /** - Translates a given piece of text. + Translates a given piece of text asynchronously. Switch to the main thread within the callback + if you want to update your UI by using `dispatch_async(dispatch_get_main_queue()) { /* code */ }`. - parameter text: The text to translate. - parameter callback: The code to be executed once the translation has completed. @@ -171,7 +172,7 @@ public class Polyglot { defer { dispatch_async(dispatch_get_main_queue()) { callback(translation: translation) - } + } } } task.resume() From 101400428a86a6fb07ac7d8ebd976aede97a1279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sat, 30 Apr 2016 14:07:13 +0200 Subject: [PATCH 2/2] Revert "Revert to main thread call" This reverts commit 4c7d4e7166bdf7eb785b0e6b3fe53d24f9a8efca. --- Polyglot/Polyglot.swift | 4 +--- PolyglotTests/PolyglotTests.swift | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Polyglot/Polyglot.swift b/Polyglot/Polyglot.swift index cacac6b..617c644 100644 --- a/Polyglot/Polyglot.swift +++ b/Polyglot/Polyglot.swift @@ -170,9 +170,7 @@ public class Polyglot { translation = self.translationFromXML(xmlString) defer { - dispatch_async(dispatch_get_main_queue()) { - callback(translation: translation) - } + callback(translation: translation) } } task.resume() diff --git a/PolyglotTests/PolyglotTests.swift b/PolyglotTests/PolyglotTests.swift index b36c9ab..3b37ff9 100644 --- a/PolyglotTests/PolyglotTests.swift +++ b/PolyglotTests/PolyglotTests.swift @@ -91,8 +91,10 @@ class PolyglotTests: XCTestCase { let polyglot: Polyglot = Polyglot(clientId: "myClientId", clientSecret: "myClientSecret") polyglot.translate("Ik weet het niet") { translation in - XCTAssertEqual(translation, "I don't know") - expectation.fulfill() + dispatch_async(dispatch_get_main_queue(), { () -> Void in + XCTAssertEqual(translation, "I don't know") + expectation.fulfill() + }) } waitForExpectationsWithTimeout(1, handler: nil)