Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show objective-c description in xcode

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

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.

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 :)

Thanks folks.

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

like image 911
OLL Avatar asked May 31 '13 11:05

OLL


1 Answers

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')

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.

like image 51
HepaKKes Avatar answered Dec 07 '22 21:12

HepaKKes