Re: Empty NSStrings, nil NSStrings
Re: Empty NSStrings, nil NSStrings
- Subject: Re: Empty NSStrings, nil NSStrings
- From: Ali Ozer <email@hidden>
- Date: Sun, 16 Apr 2006 10:29:59 -0700
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
On Apr 16, 2006, at 4:01 AM, Paolo Bertani wrote:
Hi,
I'm a bit confused about working with NSStrings that may be empty
and/or nil.
From a "Cocoa" point of view a nil NSString and an empty NSString
(a valid NSString instance containing 0 characters) can/should be
considered interchangeable?
Or should I check every NSString and, if nil, turn it into an empty
NSString before working with it (messaging or passing as parameter)?
Sorry for the very basic question...
Thank you,
Paolo.
"<Ai sensi e per gli effetti del D.Lgs. n.° 196/2003 (Codice della
Privacy) si precisa che questo messaggio, ed eventuali relativi
allegati, è strettamente riservato ai destinatari in indirizzo, con
espressa diffida di conservazione, uso, copiatura o divulgazione.
Chiunque lo riceva, non essendone destinatario, è pregato di
avvertire lo scrivente e di provvedere alla distruzione di quanto
erroneamente pervenuto>"
_______________________________________________
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
_______________________________________________
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