如何在swift的App的mainBundle中将数组保存到.plist

0 arrays plist ios swift

如何使用数组类型将数组保存到.plist?

我试试这个,但是没有用

    let path = NSBundle.mainBundle().pathForResource("Setting", ofType: "plist")
    let arrayWithProperties = NSArray(array: [
        NSNumber(integer: nowThemeSelected),
        NSNumber(integer: imageForBackgroundNumber),
        NSNumber(integer: imageForButtonNumber),
        NSNumber(integer: colorOfButton)])


    arrayWithProperties.writeToFile(path!, atomically: true)
Run Code Online (Sandbox Code Playgroud)

Dan*_*sko 5

您无法写入iOS中的主捆绑包,您的Apps捆绑包中的所有内容都是只读的.

[App的捆绑]目录包含应用程序及其所有资源.您无法写入此目录.为防止篡改,bundle目录在安装时签名.写入此目录会更改签名并阻止您的应用程序启动.但是,您可以获得对应用程序包中存储的任何资源的只读访问权限.

请考虑阅读文件系统编程指南,然后将plist保留在正确的位置.最好是Documents目录或Library目录.由你决定.