Next: Iterating over Array Elements Up: NSArray Previous: Accessing Objects in a

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.



Nicola 2002-01-13