gpt4 book ai didi

swift - LLDB 快速打印对象

转载 作者:可可西里 更新时间:2023-10-31 23:45:09 26 4
gpt4 key购买 nike

我对如何使用 LLDB 检查 swift 项目中的对象感到有点困惑。在这种特殊情况下,我使用 NSJSONSerializer 序列化一小块 JSON,我想检查值。在 Xcode 5.1 中,这非常简单,只需在 lldb 提示符下键入“po json”,我就会得到我想要的。现在命令 po 和 print 打印出大部分垃圾,使我失败。我什至尝试调用 description 属性,因为它适用于某些 swift 类型,但仍然不起作用。作为最后的手段,我使用了一个带有 println 语句的表达式,最终它起作用了。当然必须有更好更简单的方法吗?这是 LLDB 的输出:

(lldb) print json
(AnyObject?) $R4 = (instance_type = Builtin.RawPointer = 0x00007ff05c0c49d0 -> 0x0000000107ef32c8 (void *)0x0000000107ef32f0: __NSCFDictionary)
(lldb) po json
(instance_type = Builtin.RawPointer = 0x00007ff05c0c49d0 -> 0x0000000107ef32c8 (void *)0x0000000107ef32f0: __NSCFDictionary)
{
instance_type = 0x00007ff05c0c49d0 -> 0x0000000107ef32c8 (void *)0x0000000107ef32f0: __NSCFDictionary
}
(lldb) print json.description?
error: <EXPR>:1:1: error: 'Optional<AnyObject>' does not have a member named 'description'
json.description?
^ ~~~~~~~~~~~

(lldb) po json.description?
error: <EXPR>:1:1: error: 'Optional<AnyObject>' does not have a member named 'description'
json.description?
^ ~~~~~~~~~~~
(lldb) expression
Enter expressions, then terminate with an empty line to evaluate:
1 println(json)
2
Optional({
errors = {
"authorizations.provider_user_id" = (
"has already been taken"
);
};
})
(lldb)

最佳答案

你可以试试

(lldb) expr -O -d run -- json!

事实上,“po”的工作方式与 ObjC 中的工作方式不同,这是一个已知的限制。显式解包可选值,并允许对解包值进行动态类型解析应该可行

关于swift - LLDB 快速打印对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26895723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com