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 protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]