Create a directory and store files inside it in Swift

落爺英雄遲暮 提交于 2019-12-05 20:14:30

Could you try createFileAtPath for that?

func createFileAtPath(_ path: String,
         contents data: NSData?,
       attributes attr: [String : AnyObject]?) -> Bool

The same thing concerns writeToFile:

func writeToFile(_ path: String,
     options writeOptionsMask: NSDataWritingOptions) throws

where, look out, path is

The location to which to write the receiver's bytes. If path contains a tilde (~) character, you must expand it with stringByExpandingTildeInPath before invoking this method.

You should write this:

let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
var dirpath: String = paths[0] as String
let filepath = dirpath.stringByAppendingPathComponent("myOwnData.mov")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!