How to utilize default value in Root.plist for Swift app settings

858 Views Asked by At

I've set some default values for a swift app in the Root.plist file such as this:

enter image description here

My question is: how can I access the default value or utilize it? Once I load my app first time, the value is nil until I manually set it to something. As far as I can see, the only thing this does is visually give it that appearance in the settings app, but doesn't actually have a tangible value associated with it?

Side note: One thing I'd like to do if I have to manually set this is to do something like this:

UserDefaults.standard.set(DEFAULT_VALUE, forKey: "user_toggle_switch")

I'm not sure if there's any way to pull this information. Any clarification on how settings works with defaults values would be superb.

1

There are 1 best solutions below

1
On

You are confusing the two. That plist is completely different from UserDefaults.

If you want to access the values from the plist, you need to access it

if let path = Bundle.main.path(forResource: "Root", ofType: "plist") {
    if let rootDictionary = NSDictionary(contentsOfFile: path) {
        // read here
    }
 }