How to get the value of a NSNumber contained in an array while debugging ?

  • Hi,

    I am wondering how to see the value of a NSNumber in XCode debugger
    using a formatter when the said NSNumber is in a NSMutableArray ?

    To sum it up:
    - When I look at a NSNumber with the following formatter "{(int)[$VAR
    intValue]}" everything works fine and the debugger shows in the
    summary column the expected int value (112 actually :o).
    - When I put 10 NSNumber in a NSMutableArray and look at it in the
    debugger (displaying the content of the array with the little arrow),
    no way to display the value. The formatter seems ignored or invalid.

    Probably a dumb question (brand new in Cocoa/XCode) but I found no
    answer to it neither on the net nor in apple debugger documentation.
    Either I make a (stupid) mistake or I missed something in the
    formatter regarding interaction with an array. Not sure I shouldn't
    post to XCode dev list but I try here first. Feel free to redirect me.

    Yours,

    Phil
  • On 3 Aug '08, at 11:36 AM, MAGDELENAT Philippe wrote:

    > - When I put 10 NSNumber in a NSMutableArray and look at it in the
    > debugger (displaying the content of the array with the little
    > arrow), no way to display the value. The formatter seems ignored or
    > invalid.

    Use the gdb command line:

    po myArray

    This will call -description on the array and print its contents. It
    works with any Cococa collection class. If you only want to see one
    object, do:

    po [myArray objectAtIndex: 0]

    —Jens
  • If your array is called myArray, type

    po myArray

    in the debugger, and it will print the value of all objects in the array.

    Daniel

    MAGDELENAT Philippe wrote:
    > Hi,
    >
    > I am wondering how to see the value of a NSNumber in XCode debugger
    > using a formatter when the said NSNumber is in a NSMutableArray ?
    >
    > To sum it up:
    > - When I look at a NSNumber with the following formatter
    > "{(int)[$VAR intValue]}" everything works fine and the debugger shows
    > in the summary column the expected int value (112 actually :o).
    > - When I put 10 NSNumber in a NSMutableArray and look at it in the
    > debugger (displaying the content of the array with the little arrow),
    > no way to display the value. The formatter seems ignored or invalid.
    >
    > Probably a dumb question (brand new in Cocoa/XCode) but I found no
    > answer to it neither on the net nor in apple debugger documentation.
    > Either I make a (stupid) mistake or I missed something in the
    > formatter regarding interaction with an array. Not sure I shouldn't
    > post to XCode dev list but I try here first. Feel free to redirect me.
    >
    > Yours,
    >
    > Phil
  • On Sun, Aug 3, 2008 at 2:58 PM, Daniel Richman
    <applemaillist...> wrote:
    > If your array is called myArray, type
    >
    > po myArray
    >
    > in the debugger, and it will print the value of all objects in the array.

    More specifically, it will send -description to all the objects in the
    array, and print the result.  Useful even if you have an array of your
    own objects and need to inspect them in the debugger; override
    -description and return a meaningful string.

    Just be careful; by default NSData prints out everything inside of it.

    --Kyle Sluder
  • Yep found that but I want so see the value of my NSNumber in the GUI
    debgger (in XCode). I want to see my array (it shows something like 10
    objects for the summary) and then, if I open the array I want the
    summary to work for each of the NSNumber inside. Bellow you can see
    that aNumber is well shown but that the same formatter isn't working
    inside the array...

    Any idea ?Le 3 août 08 à 20:55, Jens Alfke a écrit :

    >
    > On 3 Aug '08, at 11:36 AM, MAGDELENAT Philippe wrote:
    >
    >> - When I put 10 NSNumber in a NSMutableArray and look at it in the
    >> debugger (displaying the content of the array with the little
    >> arrow), no way to display the value. The formatter seems ignored or
    >> invalid.
    >
    >
    > Use the gdb command line:
    >
    > po myArray
    >
    > This will call -description on the array and print its contents. It
    > works with any Cococa collection class. If you only want to see one
    > object, do:
    >
    > po [myArray objectAtIndex: 0]
    >
    > —Jens
  • Yep found that but I want so see the value of my NSNumber in the GUI
    debgger (in XCode). I want to see my array (it shows something like 10
    objects for the summary) and then, if I open the array I want the
    summary to work for each of the NSNumber inside. I tried to send a
    small screenshot (22k) but didn't pass. I wanted to show that a
    NSNumber is well shown but that the same formatter isn't working when
    the NSNumber is inside the array...

    I don't want to print the object in the debugger console but to
    navigate in the array dynamicaaly in the NSTable above the console in
    XCode.

    Not sure to be really clear :o)

    Thanks for any hint.

    Phil

    Le 3 août 08 à 20:55, Jens Alfke a écrit :

    >
    > On 3 Aug '08, at 11:36 AM, MAGDELENAT Philippe wrote:
    >
    >> - When I put 10 NSNumber in a NSMutableArray and look at it in the
    >> debugger (displaying the content of the array with the little
    >> arrow), no way to display the value. The formatter seems ignored or
    >> invalid.
    >
    >
    > Use the gdb command line:
    >
    > po myArray
    >
    > This will call -description on the array and print its contents. It
    > works with any Cococa collection class. If you only want to see one
    > object, do:
    >
    > po [myArray objectAtIndex: 0]
    >
    > —Jens
  • On Aug 3, 2008, at 1:39 PM, MAGDELENAT Philippe wrote:

    > Yep found that but I want so see the value of my NSNumber in the GUI
    > debgger (in XCode). I want to see my array (it shows something like
    > 10 objects for the summary) and then, if I open the array I want the
    > summary to work for each of the NSNumber inside. Bellow you can see
    > that aNumber is well shown but that the same formatter isn't working
    > inside the array...

    Data formatters have been notoriously unreliable since Xcode 1.0 or
    so. I usually turn them off, since they don't always work (as you've
    noticed), and they sometimes screw up debugging sessions, leading to a
    timeout, in which case the only remedy is to pull the plug and start
    again from the top.

    If you need to inquire about the state of objects, the best way to do
    it is manually, as long as you know that the object has been allocated.

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • That's what I start to understand... Quite strange when used to Java
    (and java ide) for the last decade :o)

    Found a guy bothered with the same problem about a year ago (http://briksoftware.com/blog/?p=24
    ). Still I am not sure to get why XCode can't do what seems (to me :o)
    a fairly simple action but it seems, considering the explanation on
    the linked page, that it comes from the way xcode works with gdb (and
    from gdb itself).

    Thanks again, I now look at the command line (a kind of return to good
    old times but hey, everything has a price :o)

    Phil

    Le 4 août 08 à 00:09, Nick Zitzmann a écrit :

    >
    > On Aug 3, 2008, at 1:39 PM, MAGDELENAT Philippe wrote:
    >
    >> Yep found that but I want so see the value of my NSNumber in the
    >> GUI debgger (in XCode). I want to see my array (it shows something
    >> like 10 objects for the summary) and then, if I open the array I
    >> want the summary to work for each of the NSNumber inside. Bellow
    >> you can see that aNumber is well shown but that the same formatter
    >> isn't working inside the array...
    >
    >
    > Data formatters have been notoriously unreliable since Xcode 1.0 or
    > so. I usually turn them off, since they don't always work (as you've
    > noticed), and they sometimes screw up debugging sessions, leading to
    > a timeout, in which case the only remedy is to pull the plug and
    > start again from the top.
    >
    > If you need to inquire about the state of objects, the best way to
    > do it is manually, as long as you know that the object has been
    > allocated.
    >
    > Nick Zitzmann
    > <http://www.chronosnet.com/>
    >
  • On 8/3/08 3:01 PM, Kyle Sluder said:

    >> If your array is called myArray, type
    >>
    >> po myArray
    >>
    >> in the debugger, and it will print the value of all objects in the array.
    >
    > More specifically, it will send -description to all the objects in the
    > array, and print the result.  Useful even if you have an array of your
    > own objects and need to inspect them in the debugger; override
    > -description and return a meaningful string.

    Actually, according to:
    <http://developer.apple.com/technotes/tn2004/tn2124.html>

    "print-object actually calls the debugDescription method of the
    specified object. NSObject implements this method by calling through to
    the description method. Thus, by default, an object's debug description
    is the same as its description. However, you can override
    debugDescription if you want to decouple these; many Cocoa objects do this."

    --
    ____________________________________________________________
    Sean McBride, B. Eng                <sean...>
    Rogue Research                        www.rogue-research.com
    Mac Software Developer              Montréal, Québec, Canada
previous month august 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today