Further to earlier answers, it’s worth pointing out you’ve got an anti-pattern 
in this code. You go:

1. Check if file exists
2. Try to read file

There is no point to step 1. Just do step 2 directly, and handle failure there.

If you _don’t_ handle failure at step 2, you’ve got yourself a nasty little 
bug/race condition, so it needs to be done anyhow.

Furthermore, use more modern APIs for reading from disk and you’ll get back an 
NSError object in the event of failure, which can be used to tell the user or 
console more information on _why_ the op failed.
e.g.
+dataWithContentsOfURL:options:error:
+propertyListWithData:options:format:error: 

Mike.

> On 9 May 2021, at 01:12, Alex Zavatone via Cocoa-dev 
> <cocoa-dev@lists.apple.com> wrote:
> 
> I’m reading a configuration plist like so.
> 
> NSFileManager *fileManager = [NSFileManager defaultManager];
>    BOOL success = [fileManager fileExistsAtPath:filePath];
> 
>    if (success) {
> 
>        _configurationDictionary = [[NSMutableDictionary 
> alloc]initWithDictionary:[NSDictionary 
> dictionaryWithContentsOfFile:filePath]];
> 
> 
> 
> 
> In some cases, I want the plist to be a dictionary.  In others, I want it to 
> be an array.
> 
> How would anyone recommend to make this a generic method to that could handle 
> if the contents of the plist was an array or a dictionary?
> 
> Thanks in advance.
> Alex Zavatone
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/mabdullah%40karelia.com
> 
> This email sent to mabdul...@karelia.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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

This email sent to arch...@mail-archive.com

Reply via email to