Write into Settings bundle in Swift

瘦欲@ 提交于 2019-12-06 05:59:51
ifau

In link that you provided has answer to your question

Note that you shouldn't read from the settings bundle directly, as it makes no sense. You should always fetch and set user defaults using NSUserDefaults. When the user makes a change in the settings application, NSUserDefaults will reflect this automatically. They will always be kept in sync.

When you create a new item in settings.bundle, you should set it identifier.

After that, you can get required value with NSUserDefaults by following way:

if let export_enabled = NSUserDefaults.standardUserDefaults().valueForKey("export_enabled") as? Bool
{
    if let export_interval = NSUserDefaults.standardUserDefaults().valueForKey("export_interval") as? Number
    {
        // ...
    }
}

And change:

NSUserDefaults.standardUserDefaults().setValue(true, forKey: "export_enabled")

Update

iOS application on device has the following structure:

AppTitle.app
    AppTitle
    AppTitleIcon.png
    Info.plist
    com.company.apptitle.plist (read/write)
    settings.bundle (readonly)

Settings.bundle intended for forming configuration hierarchy in the default Settings.app. It contains titles of sections and settings types, but settings values are stored in com.company.apptitle.plist.

Because settings.bundle is read-only, you cannot change its structure or section titles. You can only change settings values and this change occurs in com.company.apptitle.plist via NSUserDefaults.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!