Keyboard shortcuts - iOS

On iOS, the pressesBegan and pressesEnded can be used to activate shortcuts. But, you should use UIKeyCommand to add keyboard shortcuts. By adding modifierFlags you can be sure that shortcuts are not activated by accident. An additional advantage is that UIKeyCommand-shortcuts are shown when long pressing the command key.

let find = UIKeyCommand(
    input: "f", 
    modifierFlags: .command, 
    action: #selector(findContent), 
    discoverabilityTitle: "Find"
)

override var keyCommands: [UIKeyCommand]? {
    return [find]
}

@objc private func find() {
    // Logic
}