devios1 devios1 - 1 year ago 108
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

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

let filteredArray = myArray.filter {
$ != "Bob"

I have set a breakpoint inside the filter closure and just want to inspect the value of
, 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



How can I get around this?

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download