如何保存一个数组在App的mainBundle在迅疾的.plist [英] How to save an array to .plist in the App's mainBundle in swift

查看:237
本文介绍了如何保存一个数组在App的mainBundle在迅疾的.plist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何保存数组的数组类型的.plist?

我尝试这一点,但不工作

 让PATH = NSBundle.mainBundle()pathForResource(设置,ofType:plist中)。
    让arrayWithProperties = NSArray中(阵:
        的NSNumber(整数nowThemeSelected)
        的NSNumber(整数imageForBackgroundNumber)
        的NSNumber(整数imageForButtonNumber)
        的NSNumber(整数colorOfButton)])
    arrayWithProperties.writeToFile(路径!原子:真)


解决方案

您不能写在iOS的主束,你的应用程序包内的一切是只读的。


  

[应用的捆绑包]目录中包含的应用程序和所有的
  其资源。你不能写这个目录。以prevent
  篡改,捆绑目录在安装时签署。
  写这个目录更改签名,prevents您的应用程序
  发动。你可以,但是,获得只读任何访问
  存储在应用程序包的资源。


考虑读<一个href=\"https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemProgrammingGuide.pdf\"相对=nofollow>文件系统编程指南然后坚持你的plist到正确的位置。 preferably文档目录或库目录。给你。

How I can save array to .plist with array type?

I try this, but is not working

    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)

解决方案

You can't write to the main bundle in iOS, everything inside your Apps bundle is read only.

[The App's bundle ] directory contains the app and all of its resources. You cannot write to this directory. To prevent tampering, the bundle directory is signed at installation time. Writing to this directory changes the signature and prevents your app from launching. You can, however, gain read-only access to any resources stored in the apps bundle.

Consider reading the file system programming guide and then persist your plist to the correct location. Preferably the Documents directory or the Library directory. Up to you.

这篇关于如何保存一个数组在App的mainBundle在迅疾的.plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆