xcode Swift:控制台中的 Print(object) 没有显示像 NSObjects 的 Objective-C 这样的变量属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26982471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:11:45  来源:igfitidea点击:

Swift: Print(object) in console not showing variable properties like Objective-C for NSObjects

objective-cxcodedebuggingswift

提问by Shizam

I'm trying to use the console debugger (LLDB) to print out some variables but quite often the output doesn't display any of the variable's properties:

我正在尝试使用控制台调试器 (LLDB) 打印出一些变量,但输出通常不显示任何变量的属性:

p _myObjector po _myObject(neither work)

p _myObjectpo _myObject(都没有工作)

yields

产量

(myApp.SomeEntity) $R2 = 0x00007fa4aad2fda0 {
  myApp.SomeParentEntity = {
    CoreData.NSManagedObject = {
      ObjectiveC.NSObject = {}
    }
  }
}

ditto for other NSObjects, is there a special way you have to print out NSObjectsin Swift?

其他的也是如此NSObjects,是否有一种特殊的方式必须NSObjects在 Swift 中打印出来?

回答by Claire

I had the same problem with XCode 6 and Swift project.

我在 XCode 6 和 Swift 项目中遇到了同样的问题。

I finally found the explanation : On the bottom left of the Debugger console your have a Menu List with 3 options :

我终于找到了解释:在调试器控制台的左下角,您有一个包含 3 个选项的菜单列表:

  • All Output,
  • Debugger Outputand
  • Target Output.
  • 所有输出
  • 调试器输出
  • 目标输出

To see po < variableName >you have to select All outputor Debugger Output.

要查看,po < variableName >您必须选择All outputDebugger Output

回答by user1502383

Correct way:

正确做法:

po _myObject

po - print object. You can read this

po - 打印对象。你可以阅读这个