Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
How do I write this in swift? Related to UIKeyCommand

How do I convert this into swift? This code takes the keyCommand:

 export function isBackspace(keyCode: number): boolean {
      return keyCode === 8;
    }
    
    export function isDeleteForward(
      keyCode: number,
      ctrlKey: boolean,
      shiftKey: boolean,
      altKey: boolean,
      metaKey: boolean,
    ): boolean {
      if (IS_APPLE) {
        if (shiftKey || altKey || metaKey) {
          return false;
        }
        return isDelete(keyCode) || (keyCode === 68 && ctrlKey);
      }
      if (ctrlKey || altKey || metaKey) {
        return false;
      }
      return isDelete(keyCode);
    }

I have converted like this in swift:

public func isBackspace(command: UIKeyCommand) -> Bool {
  return command.input == "\u{8}"
}
public func isDeleteBackward(command: UIKeyCommand, altKey: Bool, ctrlKey: Bool, commandKey: Bool ) -> Bool {
  if altKey || commandKey {
    return false
  }

  return isBackspace(command: command) || (command.input == "H" && ctrlKey)
}

But when I press just "delete" button on keyBoard it doesn't do anything? Am I missing something here?Is the conversion right?

This is my UIKeyCommand code:

override public var keyCommands: [UIKeyCommand]? {

    let commands = [
      UIKeyCommand(input: "\u{8}", modifierFlags: .alternate, action: #selector(selectKeyTapped(command:))),
      UIKeyCommand(input: "\u{8}", modifierFlags: .command, action: #selector(selectKeyTapped(command:))),
      UIKeyCommand(input: "\u{8}", modifierFlags: .control, action: #selector(selectKeyTapped(command:))),
      UIKeyCommand(input: "\u{8}", modifierFlags: [], action: #selector(selectKeyTapped(command:)))
    ]
    if #available(iOS 15, *) {
      commands.forEach { $0.wantsPriorityOverSystemBehavior = true }
    }
    return commands
  }
@objc func selectKeyTapped(command: UIKeyCommand) {
    guard let textView = textView else { return }
    if isDeleteBackward(command: command, altKey: true, ctrlKey: true, commandKey: true) {
      if isBackspace(command: command) {
        deleteCharacter(isBackwards: true)
      } else {
        deleteCharacter(isBackwards: true)
      }
    }
  }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda