What does "+ resetStandardUserDefaults" actually do?

We tried using the "+ resetStandardUserDefaults" of the NSUserDefaults class to reset the default values ​​for their "factory" settings. It is not suitable for use. Learn from some archived discussions in SO that we should use the "removeObjectForKey" instance method to remove user preferences instead.

But I'm just curious and hope someone can explain the actual use of "+ resetStandardUserDefaults". Read the reference guide on this. But this is very short, and I do not seem to understand what it really means ...

+4
source share
1 answer

Somewhere (usually in delegate + initialize) you are declaring standard user defaults (your application preferences on first launch). + resetStandardUserDefaults makes your application signify its first launch and uses the user defaults as you declared them in the application delegate.

HAS AN INCORRECT RESPONSE ABOVE

As the Apple Documentation says:

Synchronizes any changes made to the default object for the general user and frees it from memory

The reset part refers to the fact that the standardUserDefaults object in memory is destroyed, so you will get a new file from the file system the next time you use [NSUserDefaults standardUserDefaults] , but it has nothing to do with any first run.

A call would make sense if it were renamed to flushDefaultsToDisk or similar. This is the most misleading part of the iOS SDK I've seen so far.

(I fixed this on the spot, as it appreciates the search very much and does not want to put the correction in a comment that someone cannot read.)

0
source

Source: https://habr.com/ru/post/1345546/


All Articles