gpt4 book ai didi

ios - 如何删除我的应用程序 ios swift 中存储的数据?

转载 作者:行者123 更新时间:2023-11-29 01:20:33 24 4
gpt4 key购买 nike

嗨,在我的应用程序中,我正在存储一些数据。这是我下载数​​据的代码

func downloadShow(slug: String, show: NSDictionary) {

SVProgressHUD.showWithStatus("Downloading...")
let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: sessionConfig, delegate: nil, delegateQueue: nil)
let url = NSURL(string: show["file"] as! String)
let request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "GET"
let task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
if (error == nil) {
let showFileName = url?.lastPathComponent
let programMP3Path = self.localURL + "/" + slug + "/" + showFileName!
let programDataPath = programMP3Path + ".dat"
data?.writeToFile(programMP3Path, atomically: true)
show.writeToFile(programDataPath, atomically: true)
print("Success")
SVProgressHUD.dismiss()
}
else {
// Failure
print("Faulure: \(error)");
}
})
task.resume()
}

现在我想通过单击删除按钮清除该特定数据。那么我该如何删除这些数据呢?

这是我存储数据的路径

/var/mobile/Containers/Data/Application/57EDF9A1-1108-4BA9-AE0A-57B8BA61869A/Documents/

最佳答案

您可以使用removeItemAtURL

let fileManager = NSFileManager.defaultManager()
let enumerator = fileManager.enumeratorAtURL(urlDir, includingPropertiesForKeys: nil, options: nil, errorHandler: nil)
while let file = enumerator?.nextObject() as? String {
fileManager.removeItemAtURL(urlDir.URLByAppendingPathComponent(file), error: nil)
}

关于ios - 如何删除我的应用程序 ios swift 中存储的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34649556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com