UIKeyCommand — Part 1: The Basics

What are UIKeyCommands?

Keyboard shortcut discovery screen for Beer Style Guidelines

How do I implement my own UIKeyCommand?

  • title: This is the display title of the keyboard shortcut.
  • action: This parameter points to the method that gets called from this shortcut.
  • input: This is the keyboard key (a string) that is part of the keyboard shortcut. For example, the “c” in the Copy shortcut (⌘ + c)
  • modifierFlags: This is the modifying key that is the other part of the keyboard shortcut. For example, the “⌘” in the Copy shortcut (⌘ + c)
let infoCommand = UIKeyCommand(title: "Show Info",
action: #selector(showInfo),
input: "i",
modifierFlags: .command)

Testing in the simulator.

Click this button to Send Keyboard Input to Device

Other Posts in the Series

--

--

--

Sr. iOS Engineer at Warner Bros. Digital Labs

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Frame Vs Bounds

SwiftUI | ToolBar Item

SwiftUI logo with an iPhone screesnhot

MVVM in SwiftUI

Customizing Buttons in SwiftUI iOS 15

graphic showing title of the article and Swift logo

Getting started with RealityKit

SwiftUI Tutorial: Working with Images

Scene Delegate vs AppDelegate

Introduction to SwiftUI: Declarative Programming

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan Grier

Ryan Grier

Sr. iOS Engineer at Warner Bros. Digital Labs

More from Medium

How to run Xcode 12 on macOS Monterey

What is a IOS Developer

[Measurement APIs] How to create custom Units and Dimensions (Part 2)

I developed an App from Scratch for Travellers