Search code examples
xcodeios-simulatorxcode10

What is this TouchBar button on the simulator on the new Xcode version?


What is this new Touchbbar button when running the Simulator from Xcode 10.2? The command like one?

enter image description here


Solution

  • The ⌘> on the Simulator’s Touch Bar is equivalent to the “Hardware” » “Keyboard” » “Send Keyboard Shortcuts to Device”.


    For example, let’s say your app detected command+S pressed on a physical keyboard attached to a physical device via keyCommands:

    class ViewController: UIViewController {
        override var keyCommands: [UIKeyCommand]? {
            return [UIKeyCommand(input: "s", modifierFlags: .command, action: #selector(didPressCommandS(_:)))]
        }
    
        @objc func didPressCommandS(_ keyCommand: UIKeyCommand) {
            print(#function, keyCommand)
        }
    }
    

    Usually, though, if you press command+S in the simulator it takes a screen snapshot. But if you turn on this “Send Keyboard Shortcuts to Device” (whether through the Touch Bar or via the simulator’s menu), it will call your UIKeyCommand selector, just like it would on a physical device.