ios - 快速删除plist

标签 ios swift plist

我使用NSKeyedArchiver.archiveRootObject(Any, toFile: String)函数将对象数组存储在ios的plist中。

每次调用此函数时,新数据都会添加到 plist 文件中,而不是覆盖旧数据。

我的想法是删除旧的 plist 文件并将数据写入新创建的同名 plist。

但我不知道如何用 swift 删除 plist 文件。希望有人能够提供帮助并提前致谢!

最佳答案

从系统中删除文件:

do {
    if FileManager.default.fileExists(atPath: pathToPlist) {
        try FileManager.default.removeItem(atPath: pathToPlist)
    }
} catch {
    print(error)
}

温馨提示:您无法从 bundle 中删除文件。

关于ios - 快速删除plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42440522/

相关文章:

ios - 我可以使用 XCode 中的 Settings Bundle 编辑器指定除“Settings”之外的 UI吗?

iphone - 如何在plist中存储uint32_t

objective-c - 如何区分 iOS5 上的屏幕锁定和主页按钮按下?

ios - visibleCells 返回 tableViewCell 中 collectionView 中的所有单元格

ios - 多行 NSAttributed 字符串作为 UIButton 标题

ios - 有人可以帮我解决内存泄漏问题吗?

ios - 游戏开发菜单

ios - 我可以子类化自定义 View Controller 吗

json - 在 Swift 中解码 JSON 中的 base64_encode 图像

iOS 12 Navigation Bar bar Button 在取消弹出手势时变灰