Next: 2.7 Iterating over Array Up: 2 NSArray Previous: 2.5 Accessing Objects in

2.6 Describing an Array

It is sometime useful for debugging to have a look at what is stored inside an NSArray. Nothing easier with the GNUstep base library: all methods and functions taking format arguments (in the way +stringWithFormat: does) recognise the conversion specification %@, which describes an object. So, to describe the NSArray called array, you can just do:
NSLog (@"Array: %@", array);

For example, an array created with

NSArray *array;

array = [NSArray arrayWithObjects: @"Hi", @"Hello", 
                                   AUTORELEASE ([NSLock new]), 
                                   nil];
will be described by the previous NSLog call as:
Jun 08 08:50:38 Test[16808] Array: (Hi, Hello, <NSLock: 8081f98>)

You may note that it is not as easy to get a full description of a pure C array.



2008-01-16