Created
July 11, 2016 01:53
-
-
Save wh1pch81n/732cff62978c5e8e2f0e4357cccb27c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func supportsKeyboard(lang: String?) -> Bool { | |
| guard let _lang = lang else { | |
| return false | |
| } | |
| let predicates = [ | |
| Predicate(format: "SELF == %@", "en"), | |
| Predicate(format: "SELF like[cd] %@", "en-*") | |
| ] | |
| for predicate in predicates { | |
| if NSArray(arrayLiteral: _lang).filtered(using: predicate).count > 0 { | |
| return true | |
| } | |
| } | |
| return false | |
| } | |
| supportsKeyboard(lang: nil) | |
| supportsKeyboard(lang: "en") | |
| supportsKeyboard(lang: "en-us") | |
| supportsKeyboard(lang: "jp") | |
| //// | |
| class ViewController: UIViewController { | |
| @IBOutlet weak var textField: UITextField! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| // Do any additional setup after loading the view, typically from a nib. | |
| NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardTypeDidChange(notification:)), name: NSNotification.Name.UITextInputCurrentInputModeDidChange, object: nil) | |
| } | |
| func keyboardTypeDidChange(notification: Notification) { | |
| print(">", notification) | |
| textField.placeholder = textField.textInputMode?.primaryLanguage | |
| //UITextInputMode.currentInputMode() | |
| //po UITextInputMode.activeInputModes().forEach({ print($0.primaryLanguage) }) | |
| } | |
| func selectionDidChange(_ textInput: UITextInput?) { | |
| print(textField.textInputMode?.primaryLanguage, textInput) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment