写成:
fileManager.createDirectoryAtPath(url_conversationItemList.path!, withIntermediateDirectories: true, attributes: nil) |
但是出错:
Call can throw, but it is not marked with ‘try’ and the error is not handled
改为:
let createDirOK = try fileManager.createDirectoryAtPath(url_conversationItemList.path!, withIntermediateDirectories: true, attributes: nil){ } |
结果:Extra argument ‘attributes’ in call
搜:
swift NSFileManager createDirectoryAtPath
ios – Using NSFileManager and createDirectoryAtPath in Swift – Stack Overflow
【总结】
写成:
do{ print("try create dir \(url_conversationItemList.path!)") try fileManager.createDirectoryAtPath(url_conversationItemList.path!, withIntermediateDirectories: true, attributes: nil) }catch let error as NSError{ print("create dir \(url_conversationItemList.path!) error \(error.localizedDescription)") return } |
即可。
其中:
do{ try SomeThingThatThrowable }catch let error as NSError{ print("error \(error.localizedDescription)") } |
转载请注明:在路上 » [已解决]swift中如何创建文件夹