Re: arrayWithContentsOfFile

2009-10-13 Thread Graham Cox
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

Re: arrayWithContentsOfFile

2009-10-13 Thread DKJ
On 2009-10-13, at 13:27 , I. Savant wrote: So that's exactly how the code appears? Yes. But of course I have to look in the directory before the code runs. So the file must be created somewhere before processing gets to this point. I created a test application with just this code in it,

Re: arrayWithContentsOfFile

2009-10-13 Thread I. Savant
On Oct 13, 2009, at 3:52 PM, DKJ wrote: NSArray *data; data = [NSArray arrayWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/file.plist"]]; if( data == nil ) do this;

Re: arrayWithContentsOfFile

2009-10-13 Thread James Walker
DKJ wrote: NSArray *data; data = [NSArray arrayWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/file.plist"]]; I would have used @"Documents/file.plist" as the parameter there. Your way, I wonder if you'd end up with a double slash

Re: arrayWithContentsOfFile

2009-10-13 Thread DKJ
Hmm... I ran a similar code snippet in another project, and nil is returned, as the docs say. So the file must be created somewhere else. I'll find out where. I'm glad the docs aren't wrong. dkj ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com

Re: arrayWithContentsOfFile

2009-10-13 Thread DKJ
On 2009-10-13, at 12:35 , I. Savant wrote: Again, can you post your relevant code? NSArray *data; data = [NSArray arrayWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/file.plist"]]; if( data == nil )

Re: arrayWithContentsOfFile

2009-10-13 Thread I. Savant
On Oct 13, 2009, at 3:23 PM, DKJ wrote: On 2009-10-13, at 12:12 , I. Savant wrote: Let me see if I understand what you're saying: You are expecting there to be *no* PLIST files (and so, you expect to get nil) but are getting an empty array? Bingo. Again, can you post your relevant c

Re: arrayWithContentsOfFile

2009-10-13 Thread DKJ
On 2009-10-13, at 12:12 , I. Savant wrote: Let me see if I understand what you're saying: You are expecting there to be *no* PLIST files (and so, you expect to get nil) but are getting an empty array? Bingo. ___ Cocoa-dev mailing list (Cocoa-de

Re: arrayWithContentsOfFile

2009-10-13 Thread I. Savant
On Oct 13, 2009, at 3:08 PM, DKJ wrote: I looked in the directory itself before running the code, and the plist files weren't there at all. Let me see if I understand what you're saying: You are expecting there to be *no* PLIST files (and so, you expect to get nil) but are getting an

Re: arrayWithContentsOfFile

2009-10-13 Thread DKJ
On 2009-10-13, at 12:01 , I. Savant wrote: On Oct 13, 2009, at 2:54 PM, Jens Alfke wrote: A PLIST can have an array root or a dictionary root. Are you sure your PLIST has an array root? I would still expect nil (ie, it can't create an array from a dictionary-rooted PLIST), but it's worth

Re: arrayWithContentsOfFile

2009-10-13 Thread I. Savant
On Oct 13, 2009, at 2:54 PM, Jens Alfke wrote: The docs say it returns nil if the file doesn't exist, and he's getting an empty array. That was his question. ... You must have misread his code — he's using NSHomeDirectory() as a prefix. My apologies, you're absolutely right. I read that

Re: arrayWithContentsOfFile

2009-10-13 Thread Jens Alfke
On Oct 13, 2009, at 11:49 AM, I. Savant wrote: Nope. The docs are correct and I'm betting the file you specified in fact *doesn't* exist. The docs say it returns nil if the file doesn't exist, and he's getting an empty array. That was his question. "/Documents/file.plist" is probably n

Re: arrayWithContentsOfFile

2009-10-13 Thread I. Savant
On Oct 13, 2009, at 2:43 PM, DKJ wrote: I'm using this code to read an array from a plist: NSArray *data = [NSArray arrayWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/file.plist"]]; The docs say this method returns nil when the fil

arrayWithContentsOfFile

2009-10-13 Thread DKJ
I'm using this code to read an array from a plist: NSArray *data = [NSArray arrayWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/file.plist"]]; The docs say this method returns nil when the file doesn't exist (precisely: "Returns