Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 428
devios1 Avatar asked Jun 13 '16 20:06

devios1


1 Answers

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.

like image 191
JAL Avatar answered Oct 24 '22 18:10

JAL