devios1 devios1 - 7 months ago 56
Swift Question

Print (po) the value of a Swift anonymous closure argument from the console in Xcode

I have a rather simple question I hope has a simple answer. I am using Swift's

filter
method to filter a collection of objects using the anonymous closure argument
$0
:

let filteredArray = myArray.filter {
$0.name != "Bob"
}


I have set a breakpoint inside the filter closure and just want to inspect the value of
$0
, but when I type
po $0
on the console it gives me:


(lldb) po $0

error: :2:1: error: anonymous closure argument not contained in a closure

$0

^


How can I get around this?

To be clear, the code compiles and runs, but gives me this error on the console at runtime.

JAL JAL
Answer

This is a known issue with Xcode 8.1 GM Seed. From the release notes:

Anonymous closure arguments in Swift cannot be used in LLDB expressions. For example, po $0 is not supported.

You can use the frame variable command to print its value:

fr va $0

This issue is filed as rdar://28611943.