• 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: arrayWithContentsOfFile
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: arrayWithContentsOfFile


  • Subject: Re: arrayWithContentsOfFile
  • From: Graham Cox <email@hidden>
  • Date: Wed, 14 Oct 2009 10:35:07 +1100


On 14/10/2009, at 6:52 AM, DKJ wrote:

if( data == nil )
    do this;
------------------------------------

There's no file.plist in the directory. But "do this" doesn't get done.

However, "do this" does get done when I have this:

------------------------------------
if( [data count] == 0 )
    do this;
------------------------------------

So it looks like arrayWithContentsOfFile: is returning an empty array when file.plist doesn't exist.


Note that the test for [data count] == 0 will work as a test whether the method returns nil or an empty array. If it returns nil, the message [nil count] is legal and will always return 0. So that approach catches both possibilities, so the question of whether the docs are wrong (unlikely, but I can't see the problem either) goes away.

Similarly, tests such as [string length] > 0 also catch both nil strings and empty ones, so kill two birds with one stone. You don't need to bother with things like if( string && [string length] > 0 )...

--Graham


_______________________________________________

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


References: 
 >arrayWithContentsOfFile (From: DKJ <email@hidden>)
 >Re: arrayWithContentsOfFile (From: "I. Savant" <email@hidden>)
 >Re: arrayWithContentsOfFile (From: Jens Alfke <email@hidden>)
 >Re: arrayWithContentsOfFile (From: "I. Savant" <email@hidden>)
 >Re: arrayWithContentsOfFile (From: DKJ <email@hidden>)
 >Re: arrayWithContentsOfFile (From: "I. Savant" <email@hidden>)
 >Re: arrayWithContentsOfFile (From: DKJ <email@hidden>)
 >Re: arrayWithContentsOfFile (From: "I. Savant" <email@hidden>)
 >Re: arrayWithContentsOfFile (From: DKJ <email@hidden>)

  • Prev by Date: Re: NSString Class Instance Variables
  • Next by Date: Re: NSString Class Instance Variables
  • Previous by thread: Re: arrayWithContentsOfFile
  • Next by thread: Validate NSToolbarPrintItem
  • Index(es):
    • Date
    • Thread