• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Empty NSStrings, nil NSStrings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Empty NSStrings, nil NSStrings


  • Subject: Re: Empty NSStrings, nil NSStrings
  • From: Rosyna <email@hidden>
  • Date: Sun, 16 Apr 2006 11:09:13 -0700

Ack, at 4/16/06, Ondra Cada said:

On 16.4.2006, at 19:41, Rosyna wrote:

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.

I guess this can be translated into "Never ever do something like this"

if (str) NSLog(@"First char: %C",[str characterAtIndex:0]); // WRONG!

"Always do it (somewhat like, there are many valid variations) this"

if ([str length]>0) NSLog(@"First char: %C",[str characterAtIndex:0]); // all right

Yeah, that's what I was trying to get at. In the Font Book example, some fonts may have a 0 length family name as their first entry in the name table. Which of course means to check the second entry (which won't be zero length) or get the file name.


So *never*, ever do this (which Font Book is doing) without first checking to see if the string has a >0 length.

if ([familyName characterAtIndex:0]!='.')

This will throw an exception for zero length strings.

Hmm, Ondra and I agreeing on something...

Presumably, eventually should just *any* method which can return an object and can fail work this very same way, but it is not so in Tiger, and I bet a fortune it won't in Leopard, either :)

I think I would agree with this if I understood it? But many APIs will return a non-NULL object even if an error occurs if the API returns the error.


Really, I think I'm just repeating what you said for no good reason whatsoever.
--


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


  • Follow-Ups:
    • Re: Empty NSStrings, nil NSStrings
      • From: Ondra Cada <email@hidden>
References: 
 >Empty NSStrings, nil NSStrings (From: Paolo Bertani <email@hidden>)
 >Re: Empty NSStrings, nil NSStrings (From: Ali Ozer <email@hidden>)
 >Re: Empty NSStrings, nil NSStrings (From: Rosyna <email@hidden>)
 >Re: Empty NSStrings, nil NSStrings (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Open System Preferences?
  • Next by Date: Re: Open System Preferences?
  • Previous by thread: Re: Empty NSStrings, nil NSStrings
  • Next by thread: Re: Empty NSStrings, nil NSStrings
  • Index(es):
    • Date
    • Thread