objective-c - 使用 lldb 创建 Swift 类实例变量,而不是 Objective-C
问题描述
使用我的调试器 (lldb),当它是 Objective-C 代码时,我可以轻松地创建实例类。
(lldb) e id $my_hello = [hello_from_objc new]
(lldb) po $my_hello
<hello_from_objc: 0x1c4013020>
(lldb) po [$my_hello secret_objc_method]
0x000000000000002a
(lldb) po (int) [$my_hello secret_objc_method]
42
但是当代码是纯 Swift 时,我无法弄清楚如何对 lldb 的表达式命令执行相同的操作。我很容易在 Swift 代码中创建一个实例..
let my_swift_framework = Hello_Class()
print("✔️ \(my_swift_framework.samplePublicVariable)")
解决方案
这是一个示例:执行 Swift 代码后
class HelloClass {
func hello() {
print("hello")
}
}
您可以在调试器窗口中创建一个对象:
(lldb) expression let $myHello = HelloClass()
(lldb) po $myHello
<hello_class: 0x101121180>
(lldb) po $myHello.hello()
hello
如果你得到一个错误
error: unknown type name 'let'
error: use of undeclared identifier 'HelloClass'
然后将表达式语言显式设置为 Swift:
(lldb) expression -l swift -o -- let $myHello = HelloClass()
(lldb) expression -l swift -o -- $myHello.hello()
或者您可以将 lldb 语言上下文更改回 Swift:
(lldb) settings set target.language swift
推荐阅读
- html - 将 XPath 用于类和其他属性值吗?
- .net - Microsoft Owin 在本地打破 VS
- java - 如何将这些值设置为 List
从服务器上的响应返回后? - javascript - 在原型对象Javascript中引用html元素
- java - Selenium WebDriver 获取元素 SCREEN 坐标
- reactjs - 反应引导 ul-tabs 不起作用
- javascript - 怎么画双圆?
- xml - 如何在捕获属性的同时对 aws 胶水中的嵌套 xml 标签进行分类
- cassandra - Cassandra 更新声明
- javascript - Socket.io 数组访问