从键中删除对象后,是否需要在 NSUserDefaults 中进行同步?

Do I need to do synchronize in NSUserDefaults after removing object from keys?

我找了一段时间了,如果我在做,需要同步吗:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:kType];

之后,我应该做什么?:

[[NSUserDefaults standardUserDefaults] synchronize];

这件事等你解答。

引用 this post in Whosebug, the answer from DarkDust:

The purpose of [default synchronize]; is to make the user defaults get written on disk immediately. You don't need to call it explicitly, iOS already does it at appropriate moments. So you can remove that line. In fact, it's a performance problem if you call synchronize every time you set a default.

Prior to iOS 7, the user defaults where always synchronized when the application transitioned into background. As of iOS 7 that is no longer the case so you might want to call synchronize in your app delegate's applicationDidEnterBackground: or register to the UIApplicationDidEnterBackgroundNotification notification to do that.

From the documentation for -[NSUserDefaults synchronize]:

Because this method is automatically invoked at periodic intervals, use this method only if you cannot wait for the automatic synchronization (for example, if your application is about to exit) or if you want to update the user defaults to what is on disk even though you have not made any changes.