title: Custom Keyboards Control Cursor
body: <p>Today I took a challenge to create a custom iOS keyboard that reverses the input string and displays it on the textview.<br>
  <br><strong>Input</strong>:
  <code>Hello StackOverflow!</code>
  <br><strong>Output</strong>:
  <code>!wolfrevOkcats olleH</code></p>
  
  <p>I have tried storing the button titles into a <code>[NSString]</code> array and displaying it out on the textview using <code>reverse()</code> function. <br>
  <br><strong>Here is my code</strong>:<br></p>
  
  <pre><code>  @IBAction func keyboardBtnPressed(sender: AnyObject) {
  
      let button = sender as! UIButton
      //identify the button title
      let buttonTitle = button.titleForState(.Normal)
  
      //letters and string are [NSString]() arrays.
  
      if let currentTitle = buttonTitle{
      switch currentTitle {
      case "Space":
      //if user pressed space bar, then display the result on the screen
          for letter in self.letters {
              (textDocumentProxy as! UIKeyInput).insertText(letter as String)
              letters.removeAll(keepCapacity: false)
              self.string.removeAll(keepCapacity: false)
          }
          (textDocumentProxy as! UIKeyInput).insertText(" ")
      default:
         //else append the letters to the array
          string.append(currentTitle)
          self.letters = self.string.reverse()
  
          }
      }
  
  }
  </code></pre>
  
  <p>The output:
  <code>elloH !wolfrevOkcats</code> <br> Which is not identical to: <code>!wolfrevOkcats olleH</code> <br> 
  <br>
  Is it possible for a custom keyboard to control the cursor, so instead of moving from <code>left to right</code> it goes from <code>right to left</code>?
  <br></p>
  
  <p>After doing some research I found I can edit the <code>Info.plist</code> file and change the bool value in <code>PrefersRightToLeft</code> dictionary.
  <br> This is <strong>NOT</strong> allowed.</p>
  
  <p>Is there any better way?
  Thanks.</p>