Re: KeyValue Observing rant
Re: KeyValue Observing rant
- Subject: Re: KeyValue Observing rant
- From: "Louis C. Sacha" <email@hidden>
- Date: Mon, 26 Apr 2004 16:38:32 -0700
Hello...
you can work around this by not relying on -description in
your application for anything that is displayed to the user.
If you're wanting to display the string representation of something
that could either be an NSString, an NSDate, or an NSNumber, what
would you recommend instead? Having to check for all three class
types isn't pretty.
- cricket
You might be able to use descriptionWithLocale: since most of the
built-in Cocoa collection and value classes seem to implement it (and
most seem to accept nil as the argument). Unfortunately NSString is
an exception to this (the method isn't implemented, enhancement
request?) so you would have to add your own implementation as a
category, but you could do something simple like:
@interface NSString (DescriptionWithLocaleExtension)
- (NSString *)descriptionWithLocale:(NSDictionary *)localeDictionary;
@end
@implementation NSString (DescriptionWithLocaleExtension)
- (NSString *)descriptionWithLocale:(NSDictionary *)localeDictionary
{
return [[self retain] autorelease];
}
@end
It's possible that some classes use description from within the
implementation of the descriptionWithLocale: method, which would
cause problems, and the only way to find out would be to test (which
I can't at the moment).
Of course, you could also add your own method with a default
implementation in NSObject and override it in classes where that is
necessary to provide additional information. This would give you
complete control over what is output, with only a little bit of extra
work required when you want to add specific details to the output of
the method in additional classes. In some ways, this might be the
better solution for any strings that will ultimately be displayed to
the user, since the output of description and descriptionWithLocale:
will probably never be guaranteed to be user friendly.
Hope that helps,
Louis
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.