Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When and why does NSUserDefaults' synchronize method fail?

Tags:

When and why does NSUserDefaults' synchronize method fail? What is the best way to make sure that my values are actually written and commited to NSUserDefaults, so I wouldn't have any problems restoring state after application restart?

like image 260
luvieere Avatar asked Oct 07 '09 10:10

luvieere


1 Answers

The synchronize method is a higher level API wrapper around the CFPreferencesSynchronize function. There's nothing about it in the documentation but I presume that synchronize just returns the result of CFPreferencesSynchronize. Since this CoreFoundation function can be used to synchronize host (admin) and network based preferences it can fail in some cases.

In the most common case where an app just synchronizes its user domain preferences (in the Library directory of the current user), the function usually does not fail. I think it's safe to just ignore the return value of synchronize. But that's just my opinion.

like image 168
Nikolai Ruhe Avatar answered Nov 02 '22 23:11

Nikolai Ruhe