Ios 在自定义键盘输入之前检查documentContextBeforeInput中的字符

Ios 在自定义键盘输入之前检查documentContextBeforeInput中的字符,ios,iphone,swift,swift2,custom-keyboard,Ios,Iphone,Swift,Swift2,Custom Keyboard,///注意:我的documentContext中会有很多字符,但我想检查这3个数字的“ABC”是否在一起,而不会改变。如果textfield中只有一个字符,则不起作用。比如,我需要检查uitextfield中是否有字母字符,我需要在输入视图中插入“”,但当在textfield中插入一个字符时,此代码不起作用。如果textfield中只有一个字符,则此代码不起作用。比如,我需要检查uitextfield中是否有字母字符,我需要在输入视图中插入“”,但当在textfield中插入一个字符时,此代码不

///注意:我的documentContext中会有很多字符,但我想检查这3个数字的“ABC”是否在一起,而不会改变。

如果textfield中只有一个字符,则不起作用。比如,我需要检查uitextfield中是否有字母字符,我需要在输入视图中插入“”,但当在textfield中插入一个字符时,此代码不起作用。如果textfield中只有一个字符,则此代码不起作用。比如,我需要检查uitextfield中是否有字母字符,我需要在输入视图中插入“”,但当在textfield中插入一个字符时,此代码不起作用
      ///Here is my Function  for Button press  


      @IBAction func keyPressed(_ button: UIButton) {
      var buttonTap = button.titleLabel!.text

       ///Here i call a variable for Get before input in textDocumentProxy  

     var   jukto = textDocumentProxy.documentContextBeforeInput 


      /// Now i want check if Three digits of documentContextBeforeInput is "ABC" Than it should change to "DE"

            if jukto == "ABC" {

              buttonTap  = "DE"

            }

     (textDocumentProxy as UIKeyInput).insertText("\(buttonTap!)")


    }
  @IBAction func keyPressed(_ button: UIButton) {
  var buttonTap = button.titleLabel!.text

   ///Here i call a variable for Get before input in textDocumentProxy  

 var   jukto = textDocumentProxy.documentContextBeforeInput 


  /// Now i want check if Three digits of documentContextBeforeInputis "ABC" Than it should change to "DE"


       if jukto.range(of:"ABC") != nil{ 
          buttonTap  = "DE"
        }

        (textDocumentProxy as UIKeyInput).insertText("\(buttonTap!)")


}