【问题标题】:How to show objective-c description in xcode如何在xcode中显示objective-c描述
【发布时间】:2013-05-31 11:34:17
【问题描述】:

我对@9​​87654321@ 正在谈论的 Xcode 中的“显示摘要”功能有疑问。

目前,我在我的 Objective-C 类中实现了 descriptiondebugDescription,我只需键入 po myObject 即可快速查看内容,这样可以节省我的时间。

但是,我想知道是否有办法在“显示摘要”中显示此内容。有点像有一个 NSString 时,它只是在内容窗格中向您显示字符串,而无需您进一步努力。

我也为自己的对象这样做?这会节省我很多时间:)

谢谢各位。

编辑 感谢 Martin R 的评论,我设法得到了我想要的 :) Link

【问题讨论】:

  • 您需要一些 Python 脚本。这个网站展示了它是如何工作的:stavash.wordpress.com/2013/01/06/…
  • 看准了!如果它有效(或无效),我会尝试并更新此线程。
  • 我只记得我在这里回答另一个问题时使用了“自定义摘要”作为示例:stackoverflow.com/questions/14159070/…,所以这可能也有帮助。
  • @OLL:您应该发布您的解决方案作为答案,很容易错过您的编辑。
  • 注意到.. 对此感到抱歉 - 我下次会这样做 :)

标签: objective-c xcode4


【解决方案1】:

基本上,您可以使用下面这样的 python 脚本来获取与任何对象关联的任何自定义摘要

# filename : customSummaries.py
import lldb

def someClass_summary(valueObject, dictionary):
    # get properties from object
    ivar1 = valueObject.GetChildMemberWithName('_ivar')
    ivar2 = valueObject.GetChildMemberWithName('_ivar2')

    # convert values into python intrinsics
    error = lldb.SBError()
    var1 = ivar1.GetData().GetFloat(error, 0)
    var2 = ivar2.GetData().GetDouble(error, 0)

    # string generation we're gonna use for the summaries
    valueRepr1 = str(var1)
    valueRepr2 = str(var2)

    return 'value1= ' + valueRepr1 + ', value2= ' + valueRepr2  

# this function gets called by the lldb as this script is imported
def __lldb_init_module(debugger, dict):

# this adds automatically your summaries as the script gets imported
debugger.HandleCommand('type summary add Class -F customSummaries.someClass_summary')

要在 lldb 运行时加载自定义摘要,您应该通过运行 command script import /path/to/customSummaries.py 导入上面的脚本,仅此而已。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多