• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
UserDefaults not letting me access a dictionary?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

UserDefaults not letting me access a dictionary?


  • Subject: UserDefaults not letting me access a dictionary?
  • From: Alex Hall <email@hidden>
  • Date: Sat, 14 Nov 2015 13:18:33 -0500
  • X_v_e_cd: 345d7d8c850b0a73c6d78da50c0f1104
  • X_v_r_cd: f1debc2fdc2289d1d0d0e6195263f549

Hello list,
Now I've got my Xcode machine back up and running (with an SSD, finally), I'm revisiting a couple apps I had paused. In one, I use a dictionary to store category filters in UserDefaults in [String:Bool]. I can then use something like

if let filters = userPrefs.dictionaryForKey("filters") {
	someFilterSwitch.on = filter[someCategory.rawValue]
}

someCategory is stored in a String enum and is what I use whenever I need that string, so it's constant. userPrefs, of course, is just an instance of UserDefaults. someFilterSwitch is a UISwitch; I have one for each filter in my Filters scene. I use the user prefs to turn them on or off, and update the prefs in prepareForSegue in that scene.

In a playground, accessing a dictionary of [String:Bool] works fine, as expected. In the app, though, I get an error that I can't index [String:Bool] with type 'String'. I don't understand why that is, so wanted to see if there was anything special about what UserDefaults returns. In the header file it's just an optional dictionary, and my 'if let' takes care of that. I'm not sure why else my code would error out right there, though. I haven't played much with user preferences before, so I may well be missing something, but it seems easy enough to use and there shouldn't be anything funny going on. Any thoughts? Thanks!

--
Have a great day,
Alex Hall
email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: UserDefaults not letting me access a dictionary?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Identify image file count in directory
  • Next by Date: Re: Voiceover support
  • Previous by thread: how to change the name of my variable in main.storyboard to BrowseAirports? This is what I want to call in the code when I type the code to connect to my web view?
  • Next by thread: Re: UserDefaults not letting me access a dictionary?
  • Index(es):
    • Date
    • Thread