Search code examples
iosswiftnsuserdefaultsuserdefaults

NSUserDefaults Multi Value is nil


Can somebody tell me, why I get nil, if I query

let stage = UserDefaults.standard.dictionary(forKey: "stageSelection")

my UserDefaults? There is a default vaule and I also changed the value in the settings. The settings screen is working fine - my problem is that I cannot query the selected value.

enter image description here

enter image description here


Solution

  • You're querying for a dictionary value, but there's only a String stored in UserDefaults.

    Use let stage = UserDefaults.standard.string(forKey: "stageSelection")