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
- 3 回答
- 0 关注
- 1050 浏览
添加回答
举报
0/150
提交
取消