Skip to content

Instantly share code, notes, and snippets.

@wh1pch81n
Created July 11, 2016 01:53
Show Gist options
  • Select an option

  • Save wh1pch81n/732cff62978c5e8e2f0e4357cccb27c6 to your computer and use it in GitHub Desktop.

Select an option

Save wh1pch81n/732cff62978c5e8e2f0e4357cccb27c6 to your computer and use it in GitHub Desktop.
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