tezvyn:

What LLDB command prints a UIView description versus an Int?

AI-drafted, machine-checkedSource: developer.apple.combeginner
What LLDB command prints a UIView description versus an Int?

Tests LLDB formatting at breakpoints. Great answers: po invokes description or debugDescription on objects, while p evaluates and prints raw primitive values with type info. Red flag: mixing them up or recommending console print instead of LLDB.

WHAT THIS TESTS: Whether you understand LLDB expression evaluation commands and their output formatters when paused in the debugger. The interviewer wants to know if you recognize that po and p are aliases for different expression flags and are not interchangeable.

A GOOD ANSWER COVERS: First, state that po myObject is the command for an object description because po is an alias for expression -O --, which runs the result through an object description formatter. In Objective-C this calls description; in Swift it prefers debugDescription or CustomStringConvertible. Second, state that p myInt is the command for primitives because p is an alias for expression --, which evaluates the expression and prints the raw value using LLDB type formatters, often with type annotations like Int. Third, explain the practical difference: po is optimized for human-readable object summaries, while p is general-purpose evaluation that also creates persistent variables such as 0 and 1. Fourth, mention that either command can technically evaluate any expression, but choosing the right one saves time. For example, po on a primitive in Swift may still work because of protocol conformance, yet p on an object often prints the pointer or field layout instead of the friendly description.

COMMON WRONG ANSWERS: Answering print or NSLog instead of an LLDB command. Saying po and p are identical. Claiming po only works for Objective-C objects and not Swift structs or classes. Stating that p does not work on objects at all. Failing to mention that both are aliases for the underlying expression command.

LIKELY FOLLOW-UPS: How would you evaluate a Swift expression without side effects? What is the difference between expression, expr, p, and po? How do you call a method on a paused object from the debugger? Why might po show an address instead of a description? How do you print the contents of a raw pointer or array?

ONE CONCRETE EXAMPLE: Imagine a breakpoint inside a view controller with let count = 42 and let header = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 50)). Typing p count outputs something like Int 0 = 42 and lets you reuse 0 later. Typing po header outputs a human-readable string like UIView: 0x7f8b2c40a0f0; frame = (0 0; 100 50); layer = CALayer: 0x600002b54080. Typing p header instead might print the struct layout or pointer value depending on the LLDB data formatters, which is less useful when you want a quick summary.

Read the original → developer.apple.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.