NSUserDefaults同步方法NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];[defaults setObject:@"xxxxxxxx" forKey:@"name"];[defaults synchronize];我需要知道為什么我必須使用上面代碼的最后一行[defaults synchronize]?使用它的目的是什么?這是必須的嗎?
3 回答

皈依舞
TA貢獻1851條經(jīng)驗 獲得超3個贊
你不必再寫那行了。
更新文檔中的方法參考
等待默認數(shù)據(jù)庫的任何掛起的異步更新并返回; 此方法是不必要的,不應(yīng)使用。
對該方法的評論解釋了該怎么做。
/*! -synchronize is deprecated and will be marked with the NS_DEPRECATED macro in a future release. -synchronize blocks the calling thread until all in-progress set operations have completed. This is no longer necessary. Replacements for previous uses of -synchronize depend on what the intent of calling synchronize was. If you synchronized... - ...before reading in order to fetch updated values: remove the synchronize call - ...after writing in order to notify another program to read: the other program can use KVO to observe the default without needing to notify - ...before exiting in a non-app (command line tool, agent, or daemon) process: call CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication) - ...for any other reason: remove the synchronize call */ open func synchronize() -> Bool
- 3 回答
- 0 關(guān)注
- 1097 瀏覽
添加回答
舉報
0/150
提交
取消