diff --git a/HanziPinyin.xcodeproj/project.pbxproj b/HanziPinyin.xcodeproj/project.pbxproj index bb6f8ee..c74ca20 100644 --- a/HanziPinyin.xcodeproj/project.pbxproj +++ b/HanziPinyin.xcodeproj/project.pbxproj @@ -122,11 +122,12 @@ D395A11C1CC244BB00B76FB7 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = Teambition; TargetAttributes = { D395A1241CC244BB00B76FB7 = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; }; }; @@ -188,8 +189,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"; @@ -237,8 +240,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"; @@ -258,6 +263,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -269,6 +275,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -280,6 +287,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -287,6 +295,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -297,6 +306,7 @@ PRODUCT_BUNDLE_IDENTIFIER = Teambition.HanziPinyin; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/HanziPinyin.xcodeproj/xcshareddata/xcschemes/HanziPinyin.xcscheme b/HanziPinyin.xcodeproj/xcshareddata/xcschemes/HanziPinyin.xcscheme index 6a82993..c5f834f 100644 --- a/HanziPinyin.xcodeproj/xcshareddata/xcschemes/HanziPinyin.xcscheme +++ b/HanziPinyin.xcodeproj/xcshareddata/xcschemes/HanziPinyin.xcscheme @@ -1,6 +1,6 @@ [String] { - func isValidPinyin(pinyin: String) -> Bool { + internal static func pinyinArray(withCharCodePoint charCodePoint: UInt32, outputFormat: PinyinOutputFormat = .default) -> [String] { + func isValidPinyin(_ pinyin: String) -> Bool { return pinyin != "(none0)" && pinyin.hasPrefix("(") && pinyin.hasSuffix(")") } - let codePointHex = String(format: "%x", charCodePoint).uppercaseString - guard let pinyin = HanziPinyin.sharedInstance.unicodeToPinyinTable[codePointHex] where isValidPinyin(pinyin) else { + let codePointHex = String(format: "%x", charCodePoint).uppercased() + guard let pinyin = HanziPinyin.sharedInstance.unicodeToPinyinTable[codePointHex], isValidPinyin(pinyin) else { return [] } - let leftBracketRange = pinyin.rangeOfString("(")! - let rightBracketRange = pinyin.rangeOfString(")")! - let processedPinyin = pinyin.substringWithRange(leftBracketRange.endIndex.. String in - return PinyinFormatter.formatPinyin(pinyin, withOutputFormat: outputFormat) + return PinyinFormatter.format(pinyin, withOutputFormat: outputFormat) } return formattedPinyinArray } - internal static func isHanzi(charCodePoint: UInt32) -> Bool { + internal static func isHanzi(ofCharCodePoint charCodePoint: UInt32) -> Bool { return charCodePoint >= HanziCodePoint.start && charCodePoint <= HanziCodePoint.end } } diff --git a/HanziPinyin/HanziPinyinResource.swift b/HanziPinyin/HanziPinyinResource.swift index dd6d5a1..aaba030 100644 --- a/HanziPinyin/HanziPinyinResource.swift +++ b/HanziPinyin/HanziPinyinResource.swift @@ -14,28 +14,28 @@ private struct CacheKeys { internal extension HanziPinyin { internal func initializeResource() -> [String: String] { - if let cachedPinyinTable = HanziPinyin.cachedObjectForKey(CacheKeys.unicodeToPinyin) as? [String: String] { + if let cachedPinyinTable = HanziPinyin.cachedObject(forKey: CacheKeys.unicodeToPinyin) as? [String: String] { return cachedPinyinTable } else { - let resourceBundle = NSBundle(identifier: "Teambition.HanziPinyin") ?? NSBundle.mainBundle() - guard let resourcePath = resourceBundle.pathForResource("unicode_to_hanyu_pinyin", ofType: "txt") else { + let resourceBundle = Bundle(identifier: "Teambition.HanziPinyin") ?? Bundle.main + guard let resourcePath = resourceBundle.path(forResource: "unicode_to_hanyu_pinyin", ofType: "txt") else { return [:] } do { - let unicodeToPinyinText = try NSString(contentsOfFile: resourcePath, encoding: NSUTF8StringEncoding) as String - let textComponents = unicodeToPinyinText.componentsSeparatedByString("\r\n") + let unicodeToPinyinText = try String(contentsOf: URL(fileURLWithPath: resourcePath)) + let textComponents = unicodeToPinyinText.components(separatedBy: "\r\n") var pinyinTable = [String: String]() for pinyin in textComponents { - let components = pinyin.componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) + let components = pinyin.components(separatedBy: .whitespaces) guard components.count > 1 else { continue } pinyinTable.updateValue(components[1], forKey: components[0]) } - HanziPinyin.cacheObject(pinyinTable, forKey: CacheKeys.unicodeToPinyin) + HanziPinyin.cache(pinyinTable, forKey: CacheKeys.unicodeToPinyin) return pinyinTable } catch _ { return [:] @@ -45,15 +45,15 @@ internal extension HanziPinyin { } internal extension HanziPinyin { - private static var pinYinCachePath: String? { - guard let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first else { + fileprivate static var pinYinCachePath: String? { + guard let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first else { return nil } - let pinYinCachePath = NSString(string: documentsPath).stringByAppendingPathComponent("PinYinCache") - if !NSFileManager.defaultManager().fileExistsAtPath(pinYinCachePath) { + let pinYinCachePath = NSString(string: documentsPath).appendingPathComponent("PinYinCache") + if !FileManager.default.fileExists(atPath: pinYinCachePath) { do { - try NSFileManager.defaultManager().createDirectoryAtPath(pinYinCachePath, withIntermediateDirectories: true, attributes: nil) + try FileManager.default.createDirectory(atPath: pinYinCachePath, withIntermediateDirectories: true, attributes: nil) } catch { print("create pinYin cache path error: \(error)") return nil @@ -62,34 +62,34 @@ internal extension HanziPinyin { return pinYinCachePath } - private static func pinYinCachePathForKey(key: String) -> String? { + fileprivate static func pinYinCachePath(forKey key: String) -> String? { guard let pinYinCachePath = pinYinCachePath else { return nil } - return NSString(string: pinYinCachePath).stringByAppendingPathComponent(key) + return NSString(string: pinYinCachePath).appendingPathComponent(key) } - private static func cacheObject(object: NSCoding, forKey key: String) { - let archivedData = NSKeyedArchiver.archivedDataWithRootObject(object) - guard let cachePath = pinYinCachePathForKey(key) else { + fileprivate static func cache(_ object: Any, forKey key: String) { + let archivedData = NSKeyedArchiver.archivedData(withRootObject: object) + guard let cachePath = pinYinCachePath(forKey: key) else { return } - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { + DispatchQueue.global(qos: .default).async { do { - try archivedData.writeToFile(cachePath, options: .AtomicWrite) + try archivedData.write(to: URL(fileURLWithPath: cachePath), options: .atomicWrite) } catch let error { print("cache object error: \(error)") } } } - private static func cachedObjectForKey(key: String) -> NSCoding? { - guard let cachePath = pinYinCachePathForKey(key) else { + fileprivate static func cachedObject(forKey key: String) -> Any? { + guard let cachePath = pinYinCachePath(forKey: key) else { return nil } do { - let data = try NSData(contentsOfFile: cachePath, options: []) - return NSKeyedUnarchiver.unarchiveObjectWithData(data) as? NSCoding + let data = try Data(contentsOf: URL(fileURLWithPath: cachePath), options: []) + return NSKeyedUnarchiver.unarchiveObject(with: data) } catch _ { return nil } diff --git a/HanziPinyin/PinyinFormatter.swift b/HanziPinyin/PinyinFormatter.swift index 62ace05..7ed44ba 100644 --- a/HanziPinyin/PinyinFormatter.swift +++ b/HanziPinyin/PinyinFormatter.swift @@ -9,30 +9,30 @@ import Foundation internal struct PinyinFormatter { - internal static func formatPinyin(pinyin: String, withOutputFormat format: PinyinOutputFormat) -> String { + internal static func format(_ pinyin: String, withOutputFormat format: PinyinOutputFormat) -> String { var formattedPinyin = pinyin switch format.toneType { - case .None: - formattedPinyin = formattedPinyin.stringByReplacingOccurrencesOfString("[1-5]", withString: "", options: .RegularExpressionSearch, range: formattedPinyin.startIndex.. String { + public func toPinyin(withFormat outputFormat: PinyinOutputFormat = .default, separator: String = " ") -> String { var pinyinStrings = [String]() for unicodeScalar in unicodeScalars { let charCodePoint = unicodeScalar.value - let pinyinArray = HanziPinyin.pinyinArrayWithCharCodePoint(charCodePoint, outputFormat: outputFormat) + let pinyinArray = HanziPinyin.pinyinArray(withCharCodePoint: charCodePoint, outputFormat: outputFormat) if pinyinArray.count > 0 { pinyinStrings.append(pinyinArray.first! + separator) @@ -22,28 +22,28 @@ public extension String { } } - var pinyin = pinyinStrings.joinWithSeparator("") - if !pinyin.isEmpty && pinyin.substringFromIndex(pinyin.endIndex.advancedBy(-1)) == separator { - pinyin.removeAtIndex(pinyin.endIndex.advancedBy(-1)) + var pinyin = pinyinStrings.joined(separator: "") + if !pinyin.isEmpty && pinyin.substring(from: pinyin.characters.index(pinyin.endIndex, offsetBy: -1)) == separator { + pinyin.remove(at: pinyin.characters.index(pinyin.endIndex, offsetBy: -1)) } return pinyin } - public func toPinyin(withFormat outputFormat: PinyinOutputFormat = PinyinOutputFormat.defaultFormat, separator: String = " ", completion:((pinyin: String) -> Void)) { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { + public func toPinyin(withFormat outputFormat: PinyinOutputFormat = .default, separator: String = " ", completion: @escaping ((_ pinyin: String) -> ())) { + DispatchQueue.global(qos: .default).async { let pinyin = self.toPinyin(withFormat: outputFormat, separator: separator) - dispatch_async(dispatch_get_main_queue(), { - completion(pinyin: pinyin) - }) + DispatchQueue.main.async { + completion(pinyin) + } } } - public func toPinyinAcronym(withFormat outputFormat: PinyinOutputFormat = PinyinOutputFormat.defaultFormat, separator: String = "") -> String { + public func toPinyinAcronym(withFormat outputFormat: PinyinOutputFormat = .default, separator: String = "") -> String { var pinyinStrings = [String]() for unicodeScalar in unicodeScalars { let charCodePoint = unicodeScalar.value - let pinyinArray = HanziPinyin.pinyinArrayWithCharCodePoint(charCodePoint, outputFormat: outputFormat) + let pinyinArray = HanziPinyin.pinyinArray(withCharCodePoint: charCodePoint, outputFormat: outputFormat) if pinyinArray.count > 0 { let acronym = pinyinArray.first!.characters.first! @@ -53,27 +53,27 @@ public extension String { } } - var pinyinAcronym = pinyinStrings.joinWithSeparator("") - if !pinyinAcronym.isEmpty && pinyinAcronym.substringFromIndex(pinyinAcronym.endIndex.advancedBy(-1)) == separator { - pinyinAcronym.removeAtIndex(pinyinAcronym.endIndex.advancedBy(-1)) + var pinyinAcronym = pinyinStrings.joined(separator: "") + if !pinyinAcronym.isEmpty && pinyinAcronym.substring(from: pinyinAcronym.characters.index(pinyinAcronym.endIndex, offsetBy: -1)) == separator { + pinyinAcronym.remove(at: pinyinAcronym.characters.index(pinyinAcronym.endIndex, offsetBy: -1)) } return pinyinAcronym } - public func toPinyinAcronym(withFormat outputFormat: PinyinOutputFormat = PinyinOutputFormat.defaultFormat, separator: String = "", completion:((pinyinAcronym: String) -> Void)) { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { + public func toPinyinAcronym(withFormat outputFormat: PinyinOutputFormat = .default, separator: String = "", completion: @escaping ((_ pinyinAcronym: String) -> ())) { + DispatchQueue.global(qos: .default).async { let pinyinAcronym = self.toPinyinAcronym(withFormat: outputFormat, separator: separator) - dispatch_async(dispatch_get_main_queue(), { - completion(pinyinAcronym: pinyinAcronym) - }) + DispatchQueue.main.async { + completion(pinyinAcronym) + } } } - public func hasChineseCharacter() -> Bool { + public var hasChineseCharacter: Bool { for unicodeScalar in unicodeScalars { let charCodePoint = unicodeScalar.value - if HanziPinyin.isHanzi(charCodePoint) { + if HanziPinyin.isHanzi(ofCharCodePoint: charCodePoint) { return true } } diff --git a/HanziPinyin/Supporting Files/Info.plist b/HanziPinyin/Supporting Files/Info.plist index 50325bf..a1497e5 100644 --- a/HanziPinyin/Supporting Files/Info.plist +++ b/HanziPinyin/Supporting Files/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.0.2 + 0.0.3 CFBundleSignature ???? CFBundleVersion diff --git a/HanziPinyinExample.xcodeproj/project.pbxproj b/HanziPinyinExample.xcodeproj/project.pbxproj index 08b1afd..708b920 100644 --- a/HanziPinyinExample.xcodeproj/project.pbxproj +++ b/HanziPinyinExample.xcodeproj/project.pbxproj @@ -111,11 +111,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = Teambition; TargetAttributes = { D395A1051CC243DB00B76FB7 = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; }; }; @@ -188,8 +189,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"; @@ -234,8 +237,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"; @@ -254,6 +259,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -267,6 +273,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Teambition.HanziPinyinExample; PRODUCT_NAME = HanziPinyinExample; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -278,6 +285,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Teambition.HanziPinyinExample; PRODUCT_NAME = HanziPinyinExample; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/HanziPinyinExample.xcodeproj/xcuserdata/hongxin.xcuserdatad/xcschemes/HanziPinyinExample.xcscheme b/HanziPinyinExample.xcodeproj/xcuserdata/hongxin.xcuserdatad/xcschemes/HanziPinyinExample.xcscheme index 357c92a..cda20a4 100644 --- a/HanziPinyinExample.xcodeproj/xcuserdata/hongxin.xcuserdatad/xcschemes/HanziPinyinExample.xcscheme +++ b/HanziPinyinExample.xcodeproj/xcuserdata/hongxin.xcuserdatad/xcschemes/HanziPinyinExample.xcscheme @@ -1,6 +1,6 @@ Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/HanziPinyinExample/HanziPinyinExampleViewController.swift b/HanziPinyinExample/HanziPinyinExampleViewController.swift index 291626f..6c3045f 100644 --- a/HanziPinyinExample/HanziPinyinExampleViewController.swift +++ b/HanziPinyinExample/HanziPinyinExampleViewController.swift @@ -21,28 +21,28 @@ class HanziPinyinExampleViewController: UIViewController { } deinit { - NSNotificationCenter.defaultCenter().removeObserver(self) + NotificationCenter.default.removeObserver(self) } // MARK: - Helper - private func setupUI() { + fileprivate func setupUI() { navigationItem.title = "HanziPinyin" - inputTextField.returnKeyType = .Done + inputTextField.returnKeyType = .done inputTextField.placeholder = "Chinese characters..." outputTextView.text = nil inputTextField.delegate = self - pinyinButton.enabled = false - NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(inputTextFieldTextChanged(_:)), name: UITextFieldTextDidChangeNotification, object: inputTextField) + pinyinButton.isEnabled = false + NotificationCenter.default.addObserver(self, selector: #selector(inputTextFieldTextChanged(_:)), name: .UITextFieldTextDidChange, object: inputTextField) } // MARK: - Actions - @IBAction func pinyinButtonTapped(sender: UIButton) { + @IBAction func pinyinButtonTapped(_ sender: UIButton) { guard let text = inputTextField.text else { return } inputTextField.resignFirstResponder() - let startTime = NSDate().timeIntervalSince1970 + let startTime = Date().timeIntervalSince1970 pinyinButton.startAnimating() text.toPinyin { (pinyin) in self.pinyinButton.stopAnimating() @@ -52,17 +52,17 @@ class HanziPinyinExampleViewController: UIViewController { } } - @IBAction func backgroundTapped(sender: UIControl) { - UIApplication.sharedApplication().sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, forEvent: nil) + @IBAction func backgroundTapped(_ sender: UIControl) { + UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) } - func inputTextFieldTextChanged(notification: NSNotification) { - pinyinButton.enabled = inputTextField.text?.characters.count > 0 + func inputTextFieldTextChanged(_ notification: Notification) { + pinyinButton.isEnabled = (inputTextField.text?.characters.count ?? 0) > 0 } } extension HanziPinyinExampleViewController: UITextFieldDelegate { - func textFieldShouldReturn(textField: UITextField) -> Bool { + func textFieldShouldReturn(_ textField: UITextField) -> Bool { inputTextField.resignFirstResponder() return true } diff --git a/HanziPinyinExample/Info.plist b/HanziPinyinExample/Info.plist index afd47e9..9466686 100644 --- a/HanziPinyinExample/Info.plist +++ b/HanziPinyinExample/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.0.2 + 0.0.3 CFBundleSignature ???? CFBundleVersion - 2 + 3 LSRequiresIPhoneOS UILaunchStoryboardName diff --git a/README.md b/README.md index 362c6f0..bd245e3 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ github "teambition/HanziPinyin" ###Usage ##### Pinyin output format ```swift -// PinyinToneType: None, ToneNumber -// PinyinVCharType: VCharacter, UUnicode, UAndColon -// PinyinCaseType: Lowercase, Uppercase -let outputFormat = PinyinOutputFormat(toneType: .None, vCharType: .VCharacter, caseType: .Lowercase) +// PinyinToneType: none, toneNumber +// PinyinVCharType: vCharacter, uUnicode, uAndColon +// PinyinCaseType: lowercase, uppercase +let outputFormat = PinyinOutputFormat(toneType: .none, vCharType: .vCharacter, caseType: .lowercase) ``` ##### Convert to Pinyin synchronously ```swift @@ -46,9 +46,9 @@ print("I love Chinese.".toPinyin()) ##### Chinese character detecting ```swift -print("我爱中文".hasChineseCharacter()) +print("我爱中文".hasChineseCharacter) // true -print("I love Chinese.".hasChineseCharacter()) +print("I love Chinese.".hasChineseCharacter) // false ```