0

I have a problem when running my app

Root.plist
<dict>
            <key>Type</key>
            <string>PSTextFieldSpecifier</string>
            <key>Title</key>
            <string>Token</string>
            <key>Key</key>
            <string>token_preference</string>
            <key>DefaultValue</key>
            <string>my_secret_token</string>
            <key>IsSecure</key>
            <true/>
            <key>KeyboardType</key>
            <string>Alphabet</string>
            <key>AutocapitalizationType</key>
            <string>None</string>
            <key>AutocorrectionType</key>
            <string>No</string>
        </dict>

Then I want to read this value with following:

let appDefaults = UserDefaults.standard
fglTokenValue = appDefaults.string(forKey: "token_preference")
print("TOKEN VALUE = " + fglTokenValue!)

But it always shows nil value. Why? I have declared default value in Root.plist When I will go to settings can see that default values are applied.

Robert
  • 525
  • 1
  • 6
  • 21
  • 1
    Possible duplicate of [Settings bundle values returning nil](https://stackoverflow.com/questions/36253998/settings-bundle-values-returning-nil) –  Jul 24 '18 at 14:23
  • 1
    It does not save the default values. Only if the user changes them inside the settings. You can set them when your app launches for the first time. See the post from the comment above. –  Jul 24 '18 at 14:24
  • Solution proposed here https://stackoverflow.com/questions/510216/can-you-make-the-settings-in-settings-bundle-default-even-if-you-dont-open-the/510329 by anders-cedronius (https://stackoverflow.com/users/2353816/anders-cedronius) works fine. – Robert Jul 24 '18 at 15:05

0 Answers0