假设我有一个像这样的结构:
struct MyStruct: CustomStringConvertible {
let myInt: Int
let myString: String
var description: String {
return "my int is \(myInt),\nand my string is \"\(myString)\""
}
}
Run Code Online (Sandbox Code Playgroud)
从代码打印描述工作正常.
let myStruct = MyStruct(myInt: 3, myString: "hello")
print(myStruct)
Run Code Online (Sandbox Code Playgroud)
这导致了
my int is 3,
and my string is "hello"
Run Code Online (Sandbox Code Playgroud)
当我想myStruct从调试器打印描述时出现问题.po myStruct结果是
? my int is 3,
and my string is "hello"
- myInt : 3
- myString : "hello"
Run Code Online (Sandbox Code Playgroud)
明确地打印出它的描述也没有任何帮助,因为po myStruct.description结果
"my int is 3,\nand my string is \"hello\""
Run Code Online (Sandbox Code Playgroud)
我认为这可能与此有关CustomDebugStringConvertible,所以我添加了这段代码:
extension MyStruct: CustomDebugStringConvertible {
var debugDescription: String {
return description
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这根本不会改变任何结果.
有办法吗?
my int is 3,
and my string is "hello"
Run Code Online (Sandbox Code Playgroud)
调试时从命令行打印?
(lldb) expression print(myStruct)
my int is 3,
and my string is "hello"
Run Code Online (Sandbox Code Playgroud)
你可以定义你自己的“命令”
(lldb) help command
The following subcommands are supported:
alias -- Allow users to define their own debugger command
abbreviations. This command takes 'raw' input (no need to
quote stuff).
delete -- Allow the user to delete user-defined regular expression,
python or multi-word commands.
history -- Dump the history of commands in this session.
regex -- Allow the user to create a regular expression command.
script -- A set of commands for managing or customizing script commands.
source -- Read in debugger commands from the file <filename> and execute
them.
unalias -- Allow the user to remove/delete a user-defined command
abbreviation.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1446 次 |
| 最近记录: |