在应用程序组容器中快速创建目录 [英] Create directory in app group container swift
本文介绍了在应用程序组容器中快速创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在应用程序的组容器中创建目录?
How can I go about creating a directory in my App's group container?
我尝试用作文件管理器:
I've tried using as the file manager:
let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("APP_GROUP_IDENTIFIER")!
但是不会创建目录...如何在此文件夹中创建目录?
but that doesn't create a directory...How can I go about creating a directory in this folder?
推荐答案
containerURLForSecurityApplicationGroupIdentifier
将URL返回到组容器.
要创建目录,请将新目录名称附加为路径组件
containerURLForSecurityApplicationGroupIdentifier
returns the URL to the group container.
To create a directory append the new directory name as path component
let fileManager = NSFileManager.defaultManager()
if let directory = fileManager.containerURLForSecurityApplicationGroupIdentifier("APP_GROUP_IDENTIFIER") {
let newDirectory = directory.URLByAppendingPathComponent("MyDirectory")
try? fileManager.createDirectoryAtURL(newDirectory, withIntermediateDirectories: false, attributes: nil)
}
迅速3:
let fileManager = FileManager.default
if let directory = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "APP_GROUP_IDENTIFIER") {
let newDirectory = directory.appendingPathComponent("MyDirectory")
try? fileManager.createDirectory(at: newDirectory, withIntermediateDirectories: false, attributes: nil)
}
这篇关于在应用程序组容器中快速创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文