views:

149

answers:

1

Hi there :)

I've started with objective-c/iphone programming a couple of days ago, and still having some problems converting from other languages.. I'm currently testing around with NSArrays, and NSMutableArrays, and it's really annoying that I haven't found any method for effectively displaying the contents of my arrays (without creating loops and displaying row by row).

Is there some easy method like print_r in PHP or console.log in javascript(w/Firefox && firebug) ?

Really appreciate any help :)

+2  A: 

Use NSLog, e.g.:

NSLog(@"This is my NSArray: %@", [myNSArray description]);
Alex Reynolds
that`s perfect, thanks :)
Madoc
NSLog() already calls `-description` on the object. What really needs to be done is NSLog(myArray) or NSLog(@"mArray: %@", myArray);
naixn
NSLog(myArray) will bring up a warning in SDK 3.2. I'd advise going with a formatted string. I would also advise explicitly specifying the description method.
Alex Reynolds
It is true, I always use a formatted string anyway :D. However I fail to see the point of explicitely calling description?
naixn
Issuing the description explicitly makes it absolutely clear, when reading the code, what NSLog will be showing, when dealing with types that do not offer `-description`. You don't have to use it, if you don't want to. I prefer to and would recommend this to others.
Alex Reynolds
However, it's explicitly clear if you just read the documentation... http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
Dave DeLong
Whatever. Use NSLog(myArray) if you want to, as well. *shrug*
Alex Reynolds