swift - 更改 LLDB 中的 Int 变量值
问题描述
环境: Xcode 11.3.1/Swift 5
这是功能:
func lldbTest() {
var switchInt = 1
...// do something and set a break point here
if switchInt == 1 {
print("switchInt == 1")
} else if switchInt == 2 {
print("switchInt == 2")
}
}
我在输入 if 语句之前进行调试,并在 lldb 中将 switchInt 更改为 2
e switchInt = 2
p switchInt
(Int) $R4 = 2
但它仍然打印“switchInt == 1” 结果
解决方案
我猜这种行为是因为编译器已经评估了 if 语句“if switchInt == 1”,因为在该行之前没有更改 switchInt 值的代码。我尝试了以下方法并能够获得所需的行为。
var switchInt = 1
for i in 0..<10 {
switchInt = 0
}
if switchInt == 1 { -> Put a break point here and use (lldb) e switchInt=2
print("switchInt == 1")
} else if switchInt == 2 {
print("switchInt == 2")
}
现在执行命令 p switchInt,它的值为 2。单步执行断点,它将打印 switchInt == 2。
推荐阅读
- html - 如何使触摸和鼠标响应的水平滚动导航模式?
- ios - 如何根据 Swift 中的持续时间更改 UI 中的图像
- flutter - 有没有办法在不使用材料小部件的情况下提升小部件的颤动?
- java - 在 Spring Boot 的 api 调用中,Rest 模板结果为空
- primeng - 检查 PrimeNG 复选框是选中还是未选中
- python - 如何编写一个将字典键作为列名,将字典值作为列值的excel文件?
- javascript - 从 JSON 数据填充语义 UI 表数据
- php - 禁止在 WordPress 编辑器中创建新标签 - 问题
- php - 通过 Ajax 向 PHP 验证发送 HTML 表单选择选项
- javascript - 为javascript中的每个函数获取选中的复选框值