Force 'Shared User Defaults Controller' to save to disk immediately?

I have a preferences pane that uses the Shared User Defaults Controller, which reading and saving preferences a piece of cake. It seems though that when changes are made to the fields, they aren't immediately saved to the plist fie. This creates a problem when my application needs to re-read the file immediately after the change has been made and the plist still hasn't been updated.

How can I force the preferences pane to update the preferences file immediately?


This will automatically save any change you do right away to disk:

NSUserDefaultsController *controller = [NSUserDefaultsController sharedUserDefaultsController];
[controller setAppliesImmediately:YES];

If you need this only in specific cases, you can also use and save some of the expensive I/O (you really should try to let the cache mechanism cache as much as possible instead of writing everything right away to disk):

NSUserDefaultsController *controller = [NSUserDefaultsController sharedUserDefaultsController];
[controller save:self];

Also, are you sure that you are trying to solve the right problem? You can always get the up to date version of the user defaults by querying NSUserDefaults where you don't need to care about wether the current version is cached in RAM or already written to disk.

Per the docs:

[userDefaults save:self];


[userDefaults setAppliesImmediately:YES];

Need Your Help

How to Open a page, then call a function in Master Page

c# jquery

Below is my code, I'm a beginner. But I hope I can explain my problem well, thanks in advance.

How can I convert ArrayList<Object> to ArrayList<String>?

java arraylist

ArrayList&lt;Object&gt; list = new ArrayList&lt;Object&gt;();