I'm trying to create a new folder, but I can't figure out how to use createDirectoryAtPath correctly.
According to the documentation, this is the correct syntax:
NSFileManager.createDirectoryAtPath(_:withIntermediateDirectories:attributes:error:)
I tried this:
let destinationFolder: String = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let deliverablePath: NSURL = NSURL.fileURLWithPath("\(destinationFolder)/\(arrayOfProjectIDs[index])")!
NSFileManager.createDirectoryAtPath(deliverablePath, withIntermediateDirectories: false, attributes: nil, error: nil)
But this gives me the error
Extra argument 'withIntermediateDirectories' in call
I've also tried a lot of variations, removing parameters and so on, but I can't get it to run without an error. Any ideas?
The Swift 2.0 way:
do {
var deliverablePathString = "/tmp/asdf"
try NSFileManager.defaultManager().createDirectoryAtPath(deliverablePathString, withIntermediateDirectories: false, attributes: nil)
} catch let error as NSError {
NSLog("\(error.localizedDescription)")
}
You forgot to add defaultManager()
and to convert the NSURL to String.
You can try replacing
NSFileManager.createDirectoryAtPath(deliverablePath, withIntermediateDirectories: false, attributes: nil, error: nil)
with this (converting your NSURL to String)
var deliverablePathString = deliverablePath.absoluteString
NSFileManager.defaultManager().createDirectoryAtPath(deliverablePathString, withIntermediateDirectories: false, attributes: nil, error: nil)
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With