1

After Upgrading to Xcode 7, I tried to re-run my app and I am now getting the following error:

You don’t have permission to save the file “PDF” in the folder “Documents”.

I can't figure out what the problem is, someone pls help. I've already tried clearing derived data and cleaning my project.

I saw this thread, but none of the solutions helped -> Error while build project Xcode says: "you don't have permission"

UPDATED - Here's my code:

var docsDirNew: NSURL!
var currentPath: String!

docsDirNew = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]

let unknown = docsDirNew.URLByAppendingPathComponent(dirPath)
currentPath = "\(unknown)"


var error: NSError?

    do {
        try filemgr.createDirectoryAtPath(currentPath, withIntermediateDirectories: true, attributes: nil)

        Scripts.logClass(className, message: "fileOperationsCreateDirectory >> CREATE Directory SUCCESS")
    }
    catch let error1 as NSError {

        error = error1

        Scripts.logClass(className, message: "fileOperationsCreateDirectory >> CREATE Directory FAILED >> \(error!.localizedDescription)")
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
Lavvo
  • 1,024
  • 3
  • 16
  • 35
  • Update your question with your code for getting the Documents folder reference and trying to write a file to it. – rmaddy Sep 20 '15 at 22:20

1 Answers1

5

This line:

currentPath = "\(unknown)"

should have never worked. It should be:

currentPath = unknown.path

Your original code depended on the arbitrary implementation of the NSURL description method.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • To be honest, I didn't have that line initially. I just added it trying to debug why my program was crashing after upgrading to XCode 7 because I noticed stringByAppendingPathComponent was deprecated. Either way, thanks a lot for you help cos that line worked. Now I know what to use to get the string value of my path. – Lavvo Sep 20 '15 at 22:34