Jim
Jim

Reputation: 5960

Observing changes to individual settings in NSUserDefaults

I would like to observe changes to settings values in [NSUserDefaults standardDefaults]. I am using the InAppSettingsKit to access and change settings in the program. Until now, I have just assumed all values have changed and sent notifications to all observers to update based on new values. This is not efficient and I only want to send notifications to observers when a relevant change has occurred.

Can someone suggest an efficient way to do this?

Can I assume that the value for any key from [NSUserDefaults standardDefaults] is never an array, set, or a dictionary? (Working with settings is new for me. This would probably help if I had to do a brute force scan for changes, comparing a before-dictionary with an after-dictionary. And it would not require any recursion.)

If this is already in the InAppSettingsKit, I haven't seen it, and I would be glad if someone could point it out.

Upvotes: 4

Views: 706

Answers (2)

jemeshsu
jemeshsu

Reputation: 1844

Binding is not yet available in iOS.

Upvotes: 0

jrturton
jrturton

Reputation: 119292

There is no system notification that holds the details of which default value was changed. I can't speak for inappsettings kit as I have not used it.

Your individual objects that are responding to the changes should hold local values for their relevant default settings and only perform expensive operations if necessary. Therefore responding to the notification should be a simple operation. If you have two separate objects that respond to different sub-objects within a single dafaults key then you may want to re-think how your defaults are organised. If you've got some specific examples please include them in your question.

Before rewriting your whole app to have some sort of defaults manager object in the name of "efficiency" do test to make sure that you are actually wasting significant, user-experience impacting amounts of time having lots of objects respond to the notification, otherwise you are optimising prematurely and you know what they say about that.

In answer to the second part of your question, you can't make that assumption. Any property list objects can be stored in user defaults.

Upvotes: 1

Related Questions