views:

49

answers:

1

Here is the code I am using:

NSFileManager* defaultMgr = [NSFileManager defaultManager];
if (![defaultMgr fileExistsAtPath:path]) {
 return nil;
}

Where path is a url to a file on the system like: "file://localhost/private/var/mobile/Applications/blahblahblah"

This crashes with SIGABRT when the call to fileExistsAtPath: is made. The file does exist, and perhaps the string format isn't what this method would prefer, but it should just return NO. This code is part of a very popular library, and while I don't strictly need to check the existence of the path, I really want to understand what is happening here, in case I ever need to use this method directly.

Particularly:

  1. Is the library author using this method correctly?
  2. How might one catch or expect an exception from this method?
    (The SDK docs don't discuss what exceptions might be thrown by this method.)
  3. Is this a bug that I should report to Apple?

One more detail: I am running this on my iPhone 4 device with iOS 4.1

A: 

A few issues come to mind:

1) NSFileManager works with paths not URLs. No need for "file://".

2) It needs NSStrings like @"...".

3) You should try to keep you filepaths within your application's sandbox.

No one in particular