Command | Description | Example |
---|---|---|
Value Inspection | ||
po |
Print the value of an expression | po myVariable.count |
po [object description] |
Print a detailed description of the object. | po [myView debugDescription] |
ptype |
Print the type of an expression | ptype myArray |
quick look |
Display a visual preview of an object in the debug pane | |
kvc path: "<key path>" |
Access nested properties using Key-Value Coding from the current context | kvc path: "user.profile.name" |
print |
Print a message to the console | print("My code reached here!") |
Execution Control | ||
continue |
Continue execution after a breakpoint | |
next |
Step to the next line of code | |
step |
Step into the next line of code, even if it's a function call | |
skip |
Skip the current line of code | |
return |
Return from the current function | |
Breakpoints and Watchpoints | ||
break |
Set a breakpoint at the current line of code | |
breakpoint delete <breakpoint number> |
Delete a specific breakpoint | breakpoint delete 1 |
condition break [breakpoint number] <condition> |
Set a condition for a breakpoint to trigger | condition break 1 myVariable.isEmpty |
watchpoint set expr at ` |
Set a watchpoint on an expression. | watchpoint set expr myInt == 10 at [MyViewController viewDidLoad] |
data breakpoint set at [memory address] |
Set a breakpoint on a memory address | data breakpoint set at 0x12345678 |
Information and Navigation | ||
bt |
Print the call stack | |
clear |
Clear the console output | |
help |
Get help on available debugger commands | help po |
info |
Get information about the current state of the debugger | info breakpoints |
thread list |
List all available threads | |
thread select <thread number> |
Switch to a specific thread | thread select 2 |
source file [filename] |
View the source code for a specific file | source file MyViewController.swift |
Path and URL | ||
po NSHomeDirectory() |
Print the user's home directory path | po NSHomeDirectory() |
po Bundle.main.bundleURL |
Print the URL of the app's main bundle | |
po NSBundle.mainBundle.bundlePath |
Print the path of the app's main bundle | |
po UIApplication.shared.applicationState |
Print the current application state (Active, Background, etc.) | |
po NSBundle.mainBundle.executablePath |
Print the current application location (if available) | |
Memory | ||
po <memory address> |
Print the value at a specific memory address (Careful with raw memory access!) | po 0x12345678 |
memory read <count> at <address> |
Read a specific number of bytes from memory at a given address | memory read 4 at 0x12345678 |
po CFGetAddressOfObject(<object>) |
Print the memory address of an object | po CFGetAddressOfObject(myView) |
Advanced Access | ||
po <class>.description |
Print a detailed description of an object's class | po UIViewController.description |
po NSClassFromString("<class name>") |
Access a class dynamically using its string name | po NSClassFromString("MyCustomViewController") |
po <array>[<index>] |
Access an element in an array by its index | po myArray[2] |
po <dictionary>["<key>"] |
Access a value in a dictionary by its key | po myDictionary["username"] |
po <closure>(<arguments>) |
Execute a closure directly in the debugger | po myClosure(1, "string") |
po ProcessInfo().processIdentifier |
Print the current process identifier (PID) | po ProcessInfo().processIdentifier |
po task(forPID: <PID>) |
Access a specific running process by its PID | po task(forPID: ProcessInfo().processIdentifier) |
Last active
July 2, 2024 02:12
-
-
Save akingdom/2bc37e77263c669d808470dbc91f5b29 to your computer and use it in GitHub Desktop.
Useful Xcode debugger commands
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment