Cocoa contentsOfDirectoryAtPath: error method for specific users - Mac OS X

Here is the code snippet:

// Get into the data folder of it
keychainPath = [keychainPath stringByAppendingPathComponent:@"data/default"];

DLog(@"Keychain data path: %@", keychainPath);

// Define Filemanager
NSFileManager *fm = [NSFileManager defaultManager];

// Catch any errors
NSError *dataError = nil;

// get all the files in the directory
NSArray *dataFiles = [fm contentsOfDirectoryAtPath:keychainPath error:&dataError];

if(!dataFiles)
 NSLog(@"Error: %@",dataError);

Now this works fine for most people, but some of them have reported problems, with the dataError object giving:

  Error: Error
Domain=NSCocoaErrorDomain Code=260 UserInfo=0x14d1fa10 "The folder
"default" doesnโ€™t exist." Underlying Error=(Error
Domain=NSOSStatusErrorDomain Code=-43 "The operation couldnโ€™t be
completed. (OSStatus error -43.)" (File not found))

People having this problem stated that the default file / folder exists exactly where it should be, so I have no idea why this is not working.

Any help would be appreciated!

+3
source share
1 answer

Thanks Peter, keychainPath was just some string like '~ / Library / etc.etc.'

To answer my own question:

It turns out the problem is that some Mac OS X users are confused with the tilde (~)

[keychainPath stringByExpandingTildeInPath];

, .

, , .

+3

Source: https://habr.com/ru/post/1739175/


All Articles