Is it mandatory to call NSUserDefaults synchronize method?

前端 未结 4 619
天命终不由人
天命终不由人 2020-12-16 14:36

Please, anyone, help me: Is calling NSUserDefaults\'s synchronize() method mandatory?. If I don\'t call it, what will happen? My application is wor

4条回答
  •  一整个雨季
    2020-12-16 15:04

    No.

    Since iOS12, it isn't mandatory anymore. Apple says:

    This method is unnecessary and shouldn't be used.

    You can find more information on iOS12 release note:

    UserDefaults

    NSUserDefaults has several bug fixes and improvements:

    Removed synchronization requirements. It's no longer necessary to use synchronize, CFPreferencesAppSynchronize, or CFPreferencesSynchronize. These methods will be deprecated in a future version of the OS.

    Now that you don't need to call these synchronization methods, the performance characteristics of NSUserDefaults and Preferences Utilities are slightly different: The time taken for enqueueing write operations is now paid by the writing thread, rather than by the next thread to call synchronize or do a read operation.

提交回复
热议问题