Can I change the dynamic set of Root.plist in the settings?

I have a set of settings in my application .. containing root.plist now I have a screen containing a checkbox . when I click on the checkbox I want to change the BOOL value for the DefaultValue key of PSToggleSwitchSpecifier to plist. Since this is done at runtime .. my question is .. can the file be modified at runtime, and if so, give an idea how to do this?

here is the plist:

<plist version="1.0"> <dict> <key>PreferenceSpecifiers</key> <array> <dict> <key>DefaultValue</key> <string></string> <key>Key</key> <string>Username</string> <key>Title</key> <string>Username</string> <key>Type</key> <string>PSTextFieldSpecifier</string> </dict> <dict> <key>DefaultValue</key> <string></string> <key>IsSecure</key> <true/> <key>Key</key> <string>Password</string> <key>Title</key> <string>Password</string> <key>Type</key> <string>PSTextFieldSpecifier</string> </dict> <dict> <key>Type</key> <string>PSToggleSwitchSpecifier</string> <-----toggleSwitch <key>Title</key> <string>Remember</string> <key>Key</key> <string>CheckBox</string> <key>DefaultValue</key> <----- Default Value <false/> <---- want to change this value </dict> </array> <key>Title</key> <string>Settings</string> </dict> </plist> 

thanks in advance ;)

+6
source share
2 answers

Since the set of settings is inside your application package, you cannot change it at run time, only at compile time.

You can, however, use NSUserDefaults to set the value at runtime, and the settings application will automatically reflect this. However, this will be saved elsewhere. You can simply read it in the same way as with a set of settings, also through NSUserDefaults .

Please note that you should not read directly from the parameter set, as this does not make sense. You should always select and set custom defaults using NSUserDefaults . When the user makes changes to the settings application, NSUserDefaults will reflect this automatically. They will always be synchronized.

+11
source

You cannot modify files using the application package.

+2
source

Source: https://habr.com/ru/post/894279/


All Articles