大佬教程收集整理的这篇文章主要介绍了xcode – 如何在调试时打印Swift结构的自定义描述,而不是其他内容?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
struct MyStruct: CustomStringConvertible { let myInt: Int let myString: String var description: String { return "my int is \(myint),\nand my String is \"\(myString)\"" } }
从代码打印描述工作正常.
let myStruct = MyStruct(myInt: 3,myString: "Hello") print(myStruct)
这导致了
@H_597_21@my int is 3,and my String is "Hello"
当我想从调试器打印myStruct的描述时出现问题. po myStruct导致
▿ my int is 3,and my String is "Hello" - myInt : 3 - myString : "Hello"
明确地打印出它的描述也没有帮助,因为po myStruct.description结果
"my int is 3,\nand my String is \"Hello\""
我认为它可能与CustomDebugStringConvertible有关,所以我添加了这段代码:
extension MyStruct: CustomDebugStringConvertible { var debugDescription: String { return description } }
不幸的是,这根本不会改变任何结果.
有办法吗?
@H_597_21@my int is 3,and my String is "Hello"
调试时从命令行打印?
(lldb) expression print(myStruct) my int is 3,and my String is "Hello"
你可以定义自己的’命令’
(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.
以上是大佬教程为你收集整理的xcode – 如何在调试时打印Swift结构的自定义描述,而不是其他内容?全部内容,希望文章能够帮你解决xcode – 如何在调试时打印Swift结构的自定义描述,而不是其他内容?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。