I am defining an lldb user variable as follows (no errors reported by lldb):
(lldb) expression -l swift -- let $servicesButton = unsafeBitCast(0x127979670, to: UIButton.self)
When I attempt to use the variable I get:
(lldb) po $servicesButton
error: use of undeclared identifier '$servicesButton'
(lldb) po $servicesButton.isEnabled
error: use of undeclared identifier '$servicesButton'
What am I doing wrong?
BTW: In case it matters, I broke into the debugger by clicking the Debug View Hierarchy button. I then printed the description of a UIButton and used the displayed memory address in the above unsafeBitCast.
Update: I am using Xcode 10. Here is another series of lldb commands that illustrate my problem:
(lldb) expression var $temp = 5
error: unknown type name 'var'
(lldb) expression -l swift -- var $temp = 5
(lldb) po $temp
error: use of undeclared identifier '$temp'
(lldb) expression int $xxx = 5
(lldb) po $xxx
5
Update 2: I seem to be getting somewhere:
(lldb) settings set target.language swift
(lldb) expression let $yyy = 88
(lldb) po $yyy
88
Update 3: Finally! Setting the target language does the trick. I don't know why my use of the "-l swift" option was not sufficient but I'm happy to be on my way.
(lldb) settings set target.language swift
(lldb) expression
Enter expressions, then terminate with an empty line to evaluate:
1 import UIKit
2 let $button = unsafeBitCast(0x105a23e10, to: UIButton.self)
3
(lldb) po $button
<UIButton: 0x105a23e10; frame = (134.5 3; 74 29); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x101b7b180>>
(lldb) po $button.isEnabled
false
(lldb)
help expression? Nevermind, seems like it prints the old help.expression var $foo = 5po $fooprinted5. Probably yes, it's the default Xcode 10.0