gpt4 book ai didi

ios - 如何快速将数组保存到 App 的 mainBundle 中的 .plist

转载 作者:行者123 更新时间:2023-11-28 09:46:54 24 4
gpt4 key购买 nike

如何将数组保存为数组类型的 .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)

最佳答案

您不能写入 iOS 中的主包,您的 Apps 包中的所有内容都是只读的。

[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.

考虑阅读 file system programming guide然后将您的 plist 保存到正确的位置。最好是文档目录或库目录。由你决定。

关于ios - 如何快速将数组保存到 App 的 mainBundle 中的 .plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26889507/

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