Re: Empty NSStrings, nil NSStrings
Re: Empty NSStrings, nil NSStrings
- Subject: Re: Empty NSStrings, nil NSStrings
- From: Rosyna <email@hidden>
- Date: Sun, 16 Apr 2006 10:41:58 -0700
Sometimes the fact they aren't interchangeable causes bugs. For
example, two separate bugs in Font Book are caused because it always
assumes a string will be either NULL or have a length>0. But in these
two completely separate cases, it gets an empty string, tries to call
-characterAtIndex:0, and throws an exception.
I guess my point is that never assume just because a string is not
NULL that it will not be empty. However, a simple call to [string
length] or [array count] will return 0 in both cases due to how
Objective-C handles NULL receivers.
Ack, at 4/16/06, Ali Ozer said:
Cocoa APIs usually don't treat "nil" as a valid value for strings,
arrays, etc; thus, if the return value or an argument is NSString,
it should return or take an actual string, with the empty string
always being represented by the empty string, not nil. Same with
NSArray; return an empty NSArray rather than nil. For instance
[NSView subviews] returns empty array if there are no subviews. In
such APIs passing nil in should result in an invalid argument
exception.
However, there are cases where nil is an acceptable value to
indicate various error or other conditions; in those cases, the use
of nil should be explicitly documented.
Ali
--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug
Unsanity: Unsane Tools for Insanely Great People
It's either this, or imagining Phil Schiller in a thong.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden