Tom Tom - 2 months ago 19
Swift Question

My file exists though fileExistsAtPath always returns false

I'm using the following code to detect if a file exists. The file does exist but fileExistsAtPath always returns false

if let receiptFound = receiptUrl?.checkResourceIsReachableAndReturnError(error){
print("receiptUrl is \(receiptUrl?.path)") }

print("Does the file exist \(NSFileManager.defaultManager().fileExistsAtPath(receiptUrl!.path!))")

if NSFileManager.defaultManager().fileExistsAtPath(receiptUrl!.path!)

{ //work with file

My output is:

enter image description here

I can't understand why the statement is returned as false when the file exists?


It looks to me like the URL you are messing with is outside of the app sandbox.

Your app only has access to a very limited number of directories (parts of the app bundle, documents, caches, and a few other folders). The file manager probably doesn't have any access to the StoreKit directory, and so the function fileExistsAtPath returns false.


Note that the beginning of your path is /private. That's a strong indication that the file is NOT accessible to a third party app like yours.