Re: printing arrays
Re: printing arrays
- Subject: Re: printing arrays
- From: Quincey Morris <email@hidden>
- Date: Fri, 02 Nov 2012 22:47:35 -0700
On Nov 2, 2012, at 22:18 , "Gerriet M. Denkmann" <email@hidden> wrote:
> Is there a way to make the first NSLog work?
> I seem to remember that it calls something like debuggingDescription, which, if not overridden calls description.
>
> I have no experience with swizzling.
Aren't you making things rather hard for yourself? Logging the array via a format string doesn't produce what you want, so just write a function that does:
NSString* myArrayAsString (NSArray* array) {…}
and log the return value with a %@ specifier in the normal way.
Adding a category to change the behavior of Cocoa classes seems like a pretty bad idea. Adding a category to override an existing method is a really terrible idea. (You don't know if the method was already added, or replaced, in a category.)
>> Either way, file a bug.
> Will do.
Keep in mind that the existing [NSArray description] must go out of its way to create the "bad" output. (It clearly isn't using a format specifier for string elements, or even invoking the element's 'description' method, which would be the obvious things to do.) That suggests to me that the extended-style display of characters outside of some basic character set is *deliberate*. It may be that it's been historically useful to know when there are characters in the string that might not display correctly (or at all) in the log output.
IOW, your "bad" logging may be someone else's "good" logging.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden