ft中使用NSFileManager和createDirecto

ft中使用NSFileManager和createDirecto

本文介绍了在Swift中使用NSFileManager和createDirectoryAtPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个新文件夹,但是我不知道如何正确使用createDirectoryAtPath.

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:)

我尝试过:

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)

但这给了我错误

我也尝试了很多变体,删除了参数等等,但是我不能让它没有错误地运行.有什么想法吗?

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?

推荐答案

您忘记添加defaultManager()并将NSURL转换为String.

You forgot to add defaultManager() and to convert the NSURL to String.

您可以尝试更换

NSFileManager.createDirectoryAtPath(deliverablePath, withIntermediateDirectories: false, attributes: nil, error: nil)

与此(将您的NSURL转换为字符串)

with this (converting your NSURL to String)

var deliverablePathString = deliverablePath.absoluteString

NSFileManager.defaultManager().createDirectoryAtPath(deliverablePathString, withIntermediateDirectories: false, attributes: nil, error: nil)

希望这会有所帮助

这篇关于在Swift中使用NSFileManager和createDirectoryAtPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 07:32