diff --git a/Podfile.lock b/Podfile.lock
index da68258..91c2d7b 100644
--- a/Podfile.lock
+++ b/Podfile.lock
@@ -14,4 +14,4 @@ SPEC CHECKSUMS:
Nocilla: ae0a2b05f3087b473624ac2b25903695df51246a
Polyglot: 9357934dadad89a6d68fc6f82047677349bce3df
-COCOAPODS: 0.39.0
+COCOAPODS: 0.38.2
diff --git a/Polyglot/Polyglot.swift b/Polyglot/Polyglot.swift
index 159f1a1..879f50d 100644
--- a/Polyglot/Polyglot.swift
+++ b/Polyglot/Polyglot.swift
@@ -23,8 +23,8 @@
import Foundation
/**
- Supported languages.
-*/
+ Supported languages.
+ */
public enum Language: String {
case Arabic = "ar"
case Bosnian = "bs"
@@ -117,33 +117,34 @@ public enum Language: String {
/**
Responsible for translating text.
*/
-public class Polyglot {
+open class Polyglot {
let session: Session
-
+
/// The language to be translated from. It will automatically detect the language if you do not set this.
- public var fromLanguage: Language?
+ open var fromLanguage: Language?
/// The language to translate to.
- public var toLanguage: Language
+ open var toLanguage: Language
/**
- - parameter clientId: Microsoft Translator client ID.
- - parameter clientSecret: Microsoft Translator client secret.
- */
+ - parameter clientId: Microsoft Translator client ID.
+ - parameter clientSecret: Microsoft Translator client secret.
+ */
public init(clientId: String, clientSecret: String) {
session = Session(clientId: clientId, clientSecret: clientSecret)
toLanguage = Language.English
}
-
+
/**
- 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.
*/
- public func translate(text: String, callback: ((translation: String) -> (Void))) {
+ public func translate(text: String, callback: @escaping ((_ translation: String?, _ error: Error?) -> (Void))) {
session.getAccessToken { token in
if self.fromLanguage == nil {
self.fromLanguage = text.language
@@ -152,34 +153,31 @@ public class Polyglot {
let fromLanguageComponent = (self.fromLanguage != nil) ? "&from=\(self.fromLanguage!.rawValue.urlEncoded!)" : ""
let urlString = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text=\(text.urlEncoded!)\(toLanguageComponent)\(fromLanguageComponent)"
- let request = NSMutableURLRequest(URL: NSURL(string: urlString)!)
- request.HTTPMethod = "GET"
+ var request = URLRequest(url: URL(string: urlString)!)
+ request.httpMethod = "GET"
request.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
- let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {(data, response, error) in
- let translation: String
+ let task = URLSession.shared.dataTask(with: request, completionHandler: {(data, response, error) in
+ let translation : String?
guard
let data = data,
- let xmlString = NSString(data: data, encoding: NSUTF8StringEncoding) as? String
+ let xmlString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as String?
else {
- translation = ""
return
}
-
translation = self.translationFromXML(xmlString)
-
defer {
- dispatch_async(dispatch_get_main_queue()) {
- callback(translation: translation)
+ DispatchQueue.main.async {
+ callback(translation, error)
}
}
- }
+ })
task.resume()
}
}
- private func translationFromXML(XML: String) -> String {
- let translation = XML.stringByReplacingOccurrencesOfString("", withString: "")
- return translation.stringByReplacingOccurrencesOfString("", withString: "")
+ fileprivate func translationFromXML(_ XML: String) -> String {
+ let translation = XML.replacingOccurrences(of: "", with: "")
+ return translation.replacingOccurrences(of: "", with: "")
}
}
diff --git a/Polyglot/Session.swift b/Polyglot/Session.swift
index d54b45a..01a1fd6 100644
--- a/Polyglot/Session.swift
+++ b/Polyglot/Session.swift
@@ -28,47 +28,47 @@ class Session {
let clientSecret: String
var accessToken: String?
- var expirationTime: NSDate?
+ var expirationTime: Date?
init(clientId: String, clientSecret: String) {
self.clientId = clientId
self.clientSecret = clientSecret
}
- func getAccessToken(callback: ((token: String) -> (Void))) {
+ func getAccessToken(_ callback: @escaping ((_ token: String) -> (Void))) {
if (accessToken == nil || isExpired) {
- let url = NSURL(string: "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13")
+ let url = URL(string: "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13")
- let request = NSMutableURLRequest(URL: url!)
- request.HTTPMethod = "POST"
+ var request = URLRequest(url: url!)
+ request.httpMethod = "POST"
let bodyString = "client_id=\(clientId.urlEncoded!)&client_secret=\(clientSecret.urlEncoded!)&scope=http://api.microsofttranslator.com&grant_type=client_credentials"
- request.HTTPBody = bodyString.dataUsingEncoding(NSUTF8StringEncoding)
+ request.httpBody = bodyString.data(using: String.Encoding.utf8)
- let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {(data, response, error) in
+ let task = URLSession.shared.dataTask(with: request, completionHandler: {(data, response, error) in
guard
let data = data,
- let resultsDict = try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers),
- let expiresIn = resultsDict["expires_in"] as? NSString
+ let resultsDict = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String: Any],
+ let expiresIn = resultsDict?["expires_in"] as? NSString
else {
- callback(token: "")
+ callback("")
return
}
- self.expirationTime = NSDate(timeIntervalSinceNow: expiresIn.doubleValue)
+ self.expirationTime = Date(timeIntervalSinceNow: expiresIn.doubleValue)
- let token = resultsDict["access_token"] as! String
+ let token = resultsDict?["access_token"] as! String
self.accessToken = token
- callback(token: token)
- }
+ callback(token)
+ })
task.resume()
} else {
- callback(token: accessToken!)
+ callback(accessToken!)
}
}
- private var isExpired: Bool {
- return expirationTime?.earlierDate(NSDate()) == self.expirationTime
+ fileprivate var isExpired: Bool {
+ return (expirationTime as NSDate?)?.earlierDate(Date()) == self.expirationTime
}
}
diff --git a/Polyglot/StringExtension.swift b/Polyglot/StringExtensionPolyglot.swift
similarity index 76%
rename from Polyglot/StringExtension.swift
rename to Polyglot/StringExtensionPolyglot.swift
index bfe1830..7b43bbe 100644
--- a/Polyglot/StringExtension.swift
+++ b/Polyglot/StringExtensionPolyglot.swift
@@ -25,17 +25,17 @@ import Foundation
extension String {
public var urlEncoded: String? {
- let urlQueryAllowedCharacterSet: NSMutableCharacterSet = NSCharacterSet.URLQueryAllowedCharacterSet().mutableCopy() as! NSMutableCharacterSet
- urlQueryAllowedCharacterSet.removeCharactersInString("&=?+")
- return self.stringByAddingPercentEncodingWithAllowedCharacters(urlQueryAllowedCharacterSet)
+ let urlQueryAllowedCharacterSet: NSMutableCharacterSet = (CharacterSet.urlQueryAllowed as NSCharacterSet).mutableCopy() as! NSMutableCharacterSet
+ urlQueryAllowedCharacterSet.removeCharacters(in: "&=?+")
+ return self.addingPercentEncoding(withAllowedCharacters: urlQueryAllowedCharacterSet as CharacterSet)
}
public var language: Language? {
if characters.count > 0 { // Prevent Index Out of Bounds in NSLinguisticTagger
- let tagger = NSLinguisticTagger(tagSchemes: [NSLinguisticTagSchemeLanguage], options: 0)
+ let tagger = NSLinguisticTagger(tagSchemes: [NSLinguisticTagScheme.language], options: 0)
tagger.string = self
- if let result = tagger.tagAtIndex(0, scheme: NSLinguisticTagSchemeLanguage, tokenRange: nil, sentenceRange: nil) {
- return Language(rawValue: result)
+ if let result = tagger.tag(at: 0, scheme: NSLinguisticTagScheme.language, tokenRange: nil, sentenceRange: nil) {
+ return Language(rawValue: result.rawValue)
}
}
return nil
diff --git a/PolyglotSample.xcodeproj/project.pbxproj b/PolyglotSample.xcodeproj/project.pbxproj
index 0516092..af25ef5 100644
--- a/PolyglotSample.xcodeproj/project.pbxproj
+++ b/PolyglotSample.xcodeproj/project.pbxproj
@@ -7,8 +7,10 @@
objects = {
/* Begin PBXBuildFile section */
- 6BF86B27E801452077EAF608 /* Pods_PolyglotTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 925AA115444C33786930F106 /* Pods_PolyglotTests.framework */; };
- 76E093B31C869D9803863B0A /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB9A4E55DA20E420F9D1A394 /* Pods.framework */; };
+ 00CAD5FE1F7A6CDA0090DD38 /* Polyglot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00CAD5FB1F7A6CC40090DD38 /* Polyglot.swift */; };
+ 00CAD5FF1F7A6CDA0090DD38 /* Session.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00CAD5FC1F7A6CC40090DD38 /* Session.swift */; };
+ 00CAD6001F7A6CDA0090DD38 /* StringExtensionPolyglot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00CAD5FD1F7A6CC40090DD38 /* StringExtensionPolyglot.swift */; };
+ 1FE3B86C180B8FB88CB9DA70 /* Pods_PolyglotTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E862700FF2DDDC6E779C805A /* Pods_PolyglotTests.framework */; };
B60F875D1985F1C200ABB94A /* PolyglotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B60F875C1985F1C200ABB94A /* PolyglotTests.swift */; };
B6156E3F1999D93B002CE52F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B67FC7841985F20B0030ABF8 /* Main.storyboard */; };
B6682231199C68AE00DFA909 /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6682230199C68AE00DFA909 /* StringExtensionTests.swift */; };
@@ -18,11 +20,12 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
- 169250360E8B162C09FEC696 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; };
- 18EAC8F54FC94B5025FBB495 /* Pods-PolyglotTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PolyglotTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PolyglotTests/Pods-PolyglotTests.debug.xcconfig"; sourceTree = ""; };
- 7B2717494CE9EFC17436B68F /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; };
- 906A23634E280AEDC1BA250B /* Pods-PolyglotTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PolyglotTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-PolyglotTests/Pods-PolyglotTests.release.xcconfig"; sourceTree = ""; };
- 925AA115444C33786930F106 /* Pods_PolyglotTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PolyglotTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ 00CAD5F31F7A6BE90090DD38 /* Polyglot.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Polyglot.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ 00CAD5FB1F7A6CC40090DD38 /* Polyglot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Polyglot.swift; path = Polyglot/Polyglot.swift; sourceTree = SOURCE_ROOT; };
+ 00CAD5FC1F7A6CC40090DD38 /* Session.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Session.swift; path = Polyglot/Session.swift; sourceTree = SOURCE_ROOT; };
+ 00CAD5FD1F7A6CC40090DD38 /* StringExtensionPolyglot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = StringExtensionPolyglot.swift; path = Polyglot/StringExtensionPolyglot.swift; sourceTree = SOURCE_ROOT; };
+ 12D767DA42F475C66CF8F400 /* Pods-PolyglotTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PolyglotTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-PolyglotTests/Pods-PolyglotTests.release.xcconfig"; sourceTree = ""; };
+ B0A0353E6F1D00A71C35119B /* Pods-PolyglotTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PolyglotTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PolyglotTests/Pods-PolyglotTests.debug.xcconfig"; sourceTree = ""; };
B60F87441985F1C200ABB94A /* PolyglotSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PolyglotSample.app; sourceTree = BUILT_PRODUCTS_DIR; };
B60F87561985F1C200ABB94A /* PolyglotTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PolyglotTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B60F875B1985F1C200ABB94A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
@@ -36,6 +39,7 @@
B67FC7881985F20B0030ABF8 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
B67FC7951985F2F20030ABF8 /* Polyglot-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Polyglot-Bridging-Header.h"; sourceTree = ""; };
DB9A4E55DA20E420F9D1A394 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ E862700FF2DDDC6E779C805A /* Pods_PolyglotTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PolyglotTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -43,7 +47,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- 76E093B31C869D9803863B0A /* Pods.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -51,20 +54,29 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- 6BF86B27E801452077EAF608 /* Pods_PolyglotTests.framework in Frameworks */,
+ 1FE3B86C180B8FB88CB9DA70 /* Pods_PolyglotTests.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
- 1BC459906112AA6B922B0A50 /* Pods */ = {
+ 00CAD5FA1F7A6CB40090DD38 /* Polyglot */ = {
isa = PBXGroup;
children = (
- 169250360E8B162C09FEC696 /* Pods.debug.xcconfig */,
- 7B2717494CE9EFC17436B68F /* Pods.release.xcconfig */,
- 18EAC8F54FC94B5025FBB495 /* Pods-PolyglotTests.debug.xcconfig */,
- 906A23634E280AEDC1BA250B /* Pods-PolyglotTests.release.xcconfig */,
+ 00CAD5FB1F7A6CC40090DD38 /* Polyglot.swift */,
+ 00CAD5FC1F7A6CC40090DD38 /* Session.swift */,
+ 00CAD5FD1F7A6CC40090DD38 /* StringExtensionPolyglot.swift */,
+ );
+ name = Polyglot;
+ path = "New Group";
+ sourceTree = "";
+ };
+ 02E4E4E277C02F05F31865E5 /* Pods */ = {
+ isa = PBXGroup;
+ children = (
+ B0A0353E6F1D00A71C35119B /* Pods-PolyglotTests.debug.xcconfig */,
+ 12D767DA42F475C66CF8F400 /* Pods-PolyglotTests.release.xcconfig */,
);
name = Pods;
sourceTree = "";
@@ -73,7 +85,7 @@
isa = PBXGroup;
children = (
DB9A4E55DA20E420F9D1A394 /* Pods.framework */,
- 925AA115444C33786930F106 /* Pods_PolyglotTests.framework */,
+ E862700FF2DDDC6E779C805A /* Pods_PolyglotTests.framework */,
);
name = Frameworks;
sourceTree = "";
@@ -81,11 +93,13 @@
B60F873B1985F1C200ABB94A = {
isa = PBXGroup;
children = (
+ 00CAD5FA1F7A6CB40090DD38 /* Polyglot */,
+ 00CAD5F31F7A6BE90090DD38 /* Polyglot.framework */,
B67FC7821985F20B0030ABF8 /* PolyglotSample */,
B60F87591985F1C200ABB94A /* PolyglotTests */,
B60F87451985F1C200ABB94A /* Products */,
AD05005C88874F61B93358E3 /* Frameworks */,
- 1BC459906112AA6B922B0A50 /* Pods */,
+ 02E4E4E277C02F05F31865E5 /* Pods */,
);
sourceTree = "";
};
@@ -140,7 +154,6 @@
B60F87401985F1C200ABB94A /* Sources */,
B60F87411985F1C200ABB94A /* Frameworks */,
B60F87421985F1C200ABB94A /* Resources */,
- 2C89B4C9E4725608B65AFC36 /* Embed Pods Frameworks */,
);
buildRules = (
);
@@ -155,12 +168,12 @@
isa = PBXNativeTarget;
buildConfigurationList = B60F87631985F1C200ABB94A /* Build configuration list for PBXNativeTarget "PolyglotTests" */;
buildPhases = (
- 408E75F29D9B38C4B9827AB7 /* Check Pods Manifest.lock */,
+ 7F91ED9EDFC53CF81FF9D7BE /* [CP] Check Pods Manifest.lock */,
B60F87521985F1C200ABB94A /* Sources */,
B60F87531985F1C200ABB94A /* Frameworks */,
B60F87541985F1C200ABB94A /* Resources */,
- 9C872251D11A74FF863B9D27 /* Embed Pods Frameworks */,
- CEE1C2C59E9D00E35BF90D16 /* Copy Pods Resources */,
+ EC7E49862C514AB5DB4B90DF /* [CP] Embed Pods Frameworks */,
+ 1B62D634051E7C5C83362E0B /* [CP] Copy Pods Resources */,
);
buildRules = (
);
@@ -177,16 +190,18 @@
B60F873C1985F1C200ABB94A /* Project object */ = {
isa = PBXProject;
attributes = {
- LastSwiftMigration = 0710;
LastSwiftUpdateCheck = 0710;
- LastUpgradeCheck = 0600;
+ LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Ayaka Nonaka";
TargetAttributes = {
B60F87431985F1C200ABB94A = {
CreatedOnToolsVersion = 6.0;
+ DevelopmentTeam = DB7EUU9D79;
+ LastSwiftMigration = 0900;
};
B60F87551985F1C200ABB94A = {
CreatedOnToolsVersion = 6.0;
+ LastSwiftMigration = 0900;
TestTargetID = B60F87431985F1C200ABB94A;
};
};
@@ -230,66 +245,59 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
- 2C89B4C9E4725608B65AFC36 /* Embed Pods Frameworks */ = {
+ 1B62D634051E7C5C83362E0B /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
- name = "Embed Pods Frameworks";
+ name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n";
+ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PolyglotTests/Pods-PolyglotTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
- 408E75F29D9B38C4B9827AB7 /* Check Pods Manifest.lock */ = {
+ 7F91ED9EDFC53CF81FF9D7BE /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
+ "${PODS_PODFILE_DIR_PATH}/Podfile.lock",
+ "${PODS_ROOT}/Manifest.lock",
);
- name = "Check Pods Manifest.lock";
+ name = "[CP] Check Pods Manifest.lock";
outputPaths = (
+ "$(DERIVED_FILE_DIR)/Pods-PolyglotTests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
+ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
- 9C872251D11A74FF863B9D27 /* Embed Pods Frameworks */ = {
+ EC7E49862C514AB5DB4B90DF /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
+ "${SRCROOT}/Pods/Target Support Files/Pods-PolyglotTests/Pods-PolyglotTests-frameworks.sh",
+ "${BUILT_PRODUCTS_DIR}/Nocilla/Nocilla.framework",
+ "${BUILT_PRODUCTS_DIR}/Polyglot/Polyglot.framework",
);
- name = "Embed Pods Frameworks";
+ name = "[CP] Embed Pods Frameworks";
outputPaths = (
+ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nocilla.framework",
+ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Polyglot.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PolyglotTests/Pods-PolyglotTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
- CEE1C2C59E9D00E35BF90D16 /* Copy Pods Resources */ = {
- isa = PBXShellScriptBuildPhase;
- buildActionMask = 2147483647;
- files = (
- );
- inputPaths = (
- );
- name = "Copy Pods Resources";
- outputPaths = (
- );
- runOnlyForDeploymentPostprocessing = 0;
- shellPath = /bin/sh;
- shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PolyglotTests/Pods-PolyglotTests-resources.sh\"\n";
- showEnvVarsInLog = 0;
- };
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@@ -297,8 +305,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 00CAD5FF1F7A6CDA0090DD38 /* Session.swift in Sources */,
+ 00CAD5FE1F7A6CDA0090DD38 /* Polyglot.swift in Sources */,
B67FC7891985F20B0030ABF8 /* AppDelegate.swift in Sources */,
B67FC78D1985F20B0030ABF8 /* ViewController.swift in Sources */,
+ 00CAD6001F7A6CDA0090DD38 /* StringExtensionPolyglot.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -333,20 +344,30 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
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_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
+ 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",
@@ -375,13 +396,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
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_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -389,6 +418,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;
@@ -398,42 +428,49 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
B60F87611985F1C200ABB94A /* Debug */ = {
isa = XCBuildConfiguration;
- baseConfigurationReference = 169250360E8B162C09FEC696 /* Pods.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CLANG_ENABLE_MODULES = YES;
+ DEVELOPMENT_TEAM = DB7EUU9D79;
INFOPLIST_FILE = PolyglotSample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.ayakanonaka.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = PolyglotSample;
SWIFT_OBJC_BRIDGING_HEADER = "PolyglotSample/Polyglot-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ SWIFT_SWIFT3_OBJC_INFERENCE = Off;
+ SWIFT_VERSION = 4.0;
};
name = Debug;
};
B60F87621985F1C200ABB94A /* Release */ = {
isa = XCBuildConfiguration;
- baseConfigurationReference = 7B2717494CE9EFC17436B68F /* Pods.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CLANG_ENABLE_MODULES = YES;
+ DEVELOPMENT_TEAM = DB7EUU9D79;
INFOPLIST_FILE = PolyglotSample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.ayakanonaka.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = PolyglotSample;
SWIFT_OBJC_BRIDGING_HEADER = "PolyglotSample/Polyglot-Bridging-Header.h";
+ SWIFT_SWIFT3_OBJC_INFERENCE = Off;
+ SWIFT_VERSION = 4.0;
};
name = Release;
};
B60F87641985F1C200ABB94A /* Debug */ = {
isa = XCBuildConfiguration;
- baseConfigurationReference = 18EAC8F54FC94B5025FBB495 /* Pods-PolyglotTests.debug.xcconfig */;
+ baseConfigurationReference = B0A0353E6F1D00A71C35119B /* Pods-PolyglotTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/PolyglotSample.app/PolyglotSample";
CLANG_ENABLE_MODULES = YES;
@@ -447,16 +484,19 @@
);
INFOPLIST_FILE = PolyglotTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.ayakanonaka.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "PolyglotTests/PolyglotTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ SWIFT_SWIFT3_OBJC_INFERENCE = On;
+ SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Debug;
};
B60F87651985F1C200ABB94A /* Release */ = {
isa = XCBuildConfiguration;
- baseConfigurationReference = 906A23634E280AEDC1BA250B /* Pods-PolyglotTests.release.xcconfig */;
+ baseConfigurationReference = 12D767DA42F475C66CF8F400 /* Pods-PolyglotTests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/PolyglotSample.app/PolyglotSample";
CLANG_ENABLE_MODULES = YES;
@@ -466,8 +506,11 @@
);
INFOPLIST_FILE = PolyglotTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.ayakanonaka.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "PolyglotTests/PolyglotTests-Bridging-Header.h";
+ SWIFT_SWIFT3_OBJC_INFERENCE = On;
+ SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Release;
diff --git a/PolyglotSample.xcodeproj/xcshareddata/xcschemes/PolyglotSample.xcscheme b/PolyglotSample.xcodeproj/xcshareddata/xcschemes/PolyglotSample.xcscheme
index 2f479dc..0b7f278 100644
--- a/PolyglotSample.xcodeproj/xcshareddata/xcschemes/PolyglotSample.xcscheme
+++ b/PolyglotSample.xcodeproj/xcshareddata/xcschemes/PolyglotSample.xcscheme
@@ -1,6 +1,6 @@
Bool {
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}
}
diff --git a/PolyglotSample/Base.lproj/Main.storyboard b/PolyglotSample/Base.lproj/Main.storyboard
index 61cc83e..ddc3157 100644
--- a/PolyglotSample/Base.lproj/Main.storyboard
+++ b/PolyglotSample/Base.lproj/Main.storyboard
@@ -1,13 +1,14 @@
-
+
-
+
+
-
+
@@ -16,7 +17,7 @@
-
+
@@ -27,7 +28,7 @@
-
+
diff --git a/PolyglotSample/Info.plist b/PolyglotSample/Info.plist
index 300cad6..77f6cb1 100644
--- a/PolyglotSample/Info.plist
+++ b/PolyglotSample/Info.plist
@@ -7,7 +7,7 @@
CFBundleExecutable
${EXECUTABLE_NAME}
CFBundleIdentifier
- com.ayakanonaka.${PRODUCT_NAME:rfc1034identifier}
+ $(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
@@ -22,6 +22,11 @@
1
LSRequiresIPhoneOS
+ NSAppTransportSecurity
+
+ NSAllowsArbitraryLoads
+
+
UIMainStoryboardFile
Main
UIRequiredDeviceCapabilities
diff --git a/PolyglotSample/ViewController.swift b/PolyglotSample/ViewController.swift
index 3615f59..c1c64e3 100644
--- a/PolyglotSample/ViewController.swift
+++ b/PolyglotSample/ViewController.swift
@@ -7,7 +7,6 @@
//
import UIKit
-import Polyglot
/**
@@ -41,18 +40,18 @@ 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
- translator.translate(text) { translation in
+ UIApplication.shared.isNetworkActivityIndicatorVisible = true
+ translator.translate(text: text) { translation,error in
if let language = self.translator.fromLanguage?.rawValue {
- self.translationLabel.text = "Translated from \(language.capitalizedString): \(translation)"
+ self.translationLabel.text = "Translated from \(language.capitalized): \(translation)"
}
else {
self.translationLabel.text = translation
}
- UIApplication.sharedApplication().networkActivityIndicatorVisible = false
+ UIApplication.shared.isNetworkActivityIndicatorVisible = false
}
}
}
diff --git a/PolyglotTests/Info.plist b/PolyglotTests/Info.plist
index 5293720..6d32c15 100644
--- a/PolyglotTests/Info.plist
+++ b/PolyglotTests/Info.plist
@@ -7,7 +7,7 @@
CFBundleExecutable
${EXECUTABLE_NAME}
CFBundleIdentifier
- com.ayakanonaka.${PRODUCT_NAME:rfc1034identifier}
+ $(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
diff --git a/PolyglotTests/PolyglotTests.swift b/PolyglotTests/PolyglotTests.swift
index b36c9ab..5934010 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(description: "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\"}")
@@ -90,11 +90,13 @@ class PolyglotTests: XCTestCase {
.withBody("I don't know")
let polyglot: Polyglot = Polyglot(clientId: "myClientId", clientSecret: "myClientSecret")
- polyglot.translate("Ik weet het niet") { translation in
- XCTAssertEqual(translation, "I don't know")
+ polyglot.translate("Ik weet het niet") { (translation, error) in
+
+// guard let translation = translation else { return }
+ XCTAssertEqual(translation!, "I don't know")
expectation.fulfill()
}
- waitForExpectationsWithTimeout(1, handler: nil)
+ waitForExpectations(timeout: 1, handler: nil)
}
}
diff --git a/PolyglotTests/StringExtensionTests.swift b/PolyglotTests/StringExtensionTests.swift
index 3616a46..bbf2e72 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(_ optional: @autoclosure () -> T?, _ expected: @autoclosure () -> 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)
}
}