如何将 plist 文件写入非模拟器路径



我正在用 Swift 开发一个 iOS 应用程序,我想在合理的位置(例如 ~/Documents/file.plist)为.plist文件编写NSArray

但是,当我这样做时...

var path = "~/Documents/file.plist".stringByExpandingTildeInPath
var result = array.writeToFile(path, atomically: true)
if (result) {
    println("The file was successfully written to '(path)'")
}

result的值是真的,但这个可怕的怪物打印在 Xcode 控制台中:

The file was successfully written to '/Users/dan/Library/Developer/CoreSimulator/Devices/605701BC-06E7-48BB-9B7A-2EFD04C7DC12/data/Containers/Data/Application/1DA58E4F-ED2D-4216-8E3C-76AB80B9C160/file.plist'

有没有办法告诉 Xcode 写入我指定的实际位置?

你只需要这样做。

var result = array.writeToFile("file.plist", atomically: true)

相关内容

最新更新