Re: arrayWithContentsOfFile
Re: arrayWithContentsOfFile
- Subject: Re: arrayWithContentsOfFile
- From: "I. Savant" <email@hidden>
- Date: Tue, 13 Oct 2009 14:49:49 -0400
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 file doesn't exist
(precisely: "Returns nil if the file can’t be opened..."). But the
above code gives me an empty array instead, which caused some
confusion.
Surely the docs can't be wrong...
Nope. The docs are correct and I'm betting the file you specified
in fact *doesn't* exist.
"/Documents/file.plist" is probably not a valid path. You probably
meant "~/Documents/file.plist", but that string isn't a valid path
either. Use the appropriate path-manipulating NSString methods to
expand the tilde to a full "/Users/someuser/..." path.
I'll bet that fixes things.
--
I.S.
_______________________________________________
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