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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to