亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

NSUserDefaults同步方法

NSUserDefaults同步方法

人到中年有點甜 2019-08-02 16:11:20
NSUserDefaults同步方法NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];[defaults setObject:@"xxxxxxxx" forKey:@"name"];[defaults synchronize];我需要知道為什么我必須使用上面代碼的最后一行[defaults synchronize]?使用它的目的是什么?這是必須的嗎?
查看完整描述

3 回答

?
皈依舞

TA貢獻1851條經驗 獲得超3個贊

你不必再寫那行了。

更新文檔中的方法參考

等待默認數據庫的任何掛起的異步更新并返回; 此方法是不必要的,不應使用。

對該方法的評論解釋了該怎么做。

     /*!
     -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


查看完整回答
反對 回復 2019-08-02
  • 3 回答
  • 0 關注
  • 1098 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號