user7003741
user7003741

Reputation:

Check character in documentContextBeforeInput in Custom keyboard

      ///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!)")


    }

/// Note: There will be many character in my documentContext but i want to check if "ABC" this 3 digits is together than it will be change.

Upvotes: 0

Views: 460

Answers (1)

S.Ali Haider
S.Ali Haider

Reputation: 46

  @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!)")


}

Upvotes: 2

Related Questions