如何在Xcode中显示Objective-C描述 [英] How to show objective-c description in xcode

查看:75
本文介绍了如何在Xcode中显示Objective-C描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Xcode中的显示摘要"功能有疑问,这家伙正在谈论.

I have a question about the "Show Summaries" feature in Xcode which this guys is talking about.

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

Currently, I implement description and debugDescription in my Objective-C classes to that I can just type po myObject to get a quick view of the content and this saves me time.

但是,我想知道是否有一种方法可以在显示摘要"中显示此内容.有点像拥有NSString一样,它只是在内容"窗格中向您显示该字符串,而无需您做进一步的工作.

However, I want to know if there's a way to get this to show in this "Show Summaries" thing. Kind of like when of have an NSString, it just shows you the string in Content pane without further effort from you.

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

And I do this for my own objects too? This would save me so much time :)

谢谢大家.

修改 多亏了Martin R的评论,我终于得到了想要的东西:) 链接

Edit Thanks to Martin R's comment I managed to get what I wanted :) Link

推荐答案

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

Basically you could use a python script like this one right below to get any custom summary associated to any object

# 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导入上面的脚本,仅此而已.

To load the custom summaries while the lldb is running you should import the script above by running command script import /path/to/customSummaries.py and that's all.

这篇关于如何在Xcode中显示Objective-C描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆