Run and debug
Breakpoints, variables and the console, attaching to a running app, launch arguments, and slow first sessions on a device.
Debug your iOS app in VS Code, on an iPhone or the simulator. Pick a device, set breakpoints and press Cmd+R or F5. No configuration needed.
While debugging
- Breakpoints work in Swift, Objective-C, C and C++, including conditional breakpoints and logpoints.
- Variables, watch, call stack and threads are in VS Code's standard debug view.
- The Debug Console accepts lldb commands such as po self and bt.
- The app's print / NSLog output is in Output › kxapp Console.
- Stopping the session ends the app, as in Xcode. To keep the app running, turn off kxapp.debug.killAppOnStop.
The build happens before the debug session starts, so Restart on the debug toolbar doesn't recompile. After changing code, press Cmd+R to build and run again.
Attaching to a running app
Run "Attach to Running App…" from the Command Palette and pick an app running on the device (shown with its name, pid and bundle id). The app keeps running after you detach.
launch.json
To pin a scheme or device, or to pass launch arguments, add a configuration of type kxapp to .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{ "type": "kxapp", "request": "launch", "name": "kxapp: Build & Run", "build": true },
{ "type": "kxapp", "request": "launch", "name": "kxapp: Run", "build": false },
{ "type": "kxapp", "request": "attach", "name": "kxapp: Attach" }
]
}| Field | Description |
|---|---|
| scheme | Scheme to build and run; defaults to the current selection |
| configuration | Build configuration; defaults to the current selection |
| device | UDID or name of the simulator or device; defaults to the run destination |
| build | Build before running; defaults to true |
| args | Launch arguments for the app |
| env | Environment variables for the app |
| pid | (attach) Process to attach to; pick from running apps when omitted |
The first debug session on a device is slow
After an iPhone updates its OS, Xcode has to prepare it once, otherwise the first debug session starts very slowly. When that happens the extension tells you: open Xcode's Window › Devices and Simulators, connect the device once and let Xcode finish preparing it. After that, breakpoints hit within seconds.
For other launch failures (locked device, signing problems and so on) the extension shows the actual reason; see Troubleshooting.