title: iOS9 Swift File Creating NSFileManager.createDirectoryAtPath with NSURL
body: <p>Before iOS9, we had created a directory like so</p>
  
  <pre><code>let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
  let logsPath = documentsPath.stringByAppendingPathComponent("logs")
  let errorPointer = NSErrorPointer()
  NSFileManager.defaultManager().createDirectoryAtPath(logsPath, withIntermediateDirectories: true, attributes: nil, error: errorPointer)
  </code></pre>
  
  <p>But with iOS9 they removed String.stringByAppendingPathComponent. The auto convert tool replaced our use of String with NSURL. createDirectoryAtPath() takes a string so I need to convert the NSURL to a string. We used absolutePath like so: (update for iOS9)</p>
  
  <pre><code>let documentsPath = NSURL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0])
  let logsPath = documentsPath.URLByAppendingPathComponent("logs")
  do {
      try NSFileManager.defaultManager().createDirectoryAtPath(logsPath.absoluteString, withIntermediateDirectories: true, attributes: nil)
  } catch let error as NSError {
      NSLog("Unable to create directory \(error.debugDescription)")
  }
  </code></pre>
  
  <p>But I am getting the following error:</p>
  
  <blockquote>
    <p>Unable to create directory Error Domain=NSCocoaErrorDomain Code=513
    "You don’t have permission to save the file “logs” in the folder
    “Documents”."
    UserInfo={NSFilePath=file:///var/mobile/Containers/Data/Application/F2EF2D4F-94AF-4BF2-AF9E-D0ECBC8637E7/Documents/logs/,
    NSUnderlyingError=0x15664d070 {Error Domain=NSPOSIXErrorDomain Code=1
    "Operation not permitted"}}</p>
  </blockquote>