最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

[已解决]swift中如何创建文件夹

Swift crifan 918浏览 0评论

写成:

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中如何创建文件夹

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
61 queries in 0.108 seconds, using 18.82MB memory