使用Swift REPL时,每次为变量赋值时,都会显示该值的整个转储。我想抑制它,因为当它是一个大型结构的实例时,它会完全消除前面的行。
1 > let a = SomethingComplex()
a: SomethingComplex = {
list = 3 values {
[0] = {
edges = 4 values {
[0] = {
id = 1
from = 0x0000000100506110 {
edges = 4 values {
[0] = {
id = 3
from = 0x0000000100506a50 {
edges = 4 values {
[0] = {
id = 5
from = 0x0000000100506820 {...}
to = 0x0000000100506a50 {...}
}
.
.
.
有没有办法压制这个?
答案 0 :(得分:2)
Swift REPL在lldb调试器的上下文中运行,默认情况下, 打印表达式中声明的变量的值。 这由lldb变量
控制print-decls -- If true, LLDB will print the values of variables declared in an expression. Currently only supported in the REPL (default: true).
(在Swift REPL中使用:set list
获取所有lldb变量的列表。)
所以你可以抑制变量声明的输出
通过将该变量设置为false
。示例(注意一个领先的
冒号用于发出lldb命令):
$ swift Welcome to Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.39.1). Type :help for assistance. 1> struct SomethingComplex { let x = 1; let y = 2 } 2> let a = SomethingComplex() a: SomethingComplex = { x = 1 y = 2 } 3> :set set print-decls false 3> let b = SomethingComplex() 4>