保存 NSUserDefaults 完成

发布于 2024-09-25 09:29:37 字数 320 浏览 2 评论 0原文

我注意到 NSUserDefaults 的保存需要一段时间。

如何查看是否保存完成?

例如我这样做:

NSMutableArray *uld = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"testdata"]];
[uld addObject:teststring];
[[NSUserDefaults standardUserDefaults] setObject:uld forKey:@"testdata"];

I have noticed that the saving of NSUserDefaults takes a while.

How can I check if it has finished saving?

for example I do:

NSMutableArray *uld = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"testdata"]];
[uld addObject:teststring];
[[NSUserDefaults standardUserDefaults] setObject:uld forKey:@"testdata"];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星軌x 2024-10-02 09:29:37

您通常不必担心 NSUserDefaults 它会在有时间的时候存储更改,如果您需要确保更改已写入磁盘,请调用 - (BOOL) synchronise,如果默认值已正确写入光盘,它将返回 YES

请参阅 NSUserDefaults 参考页< /a> 在苹果

You normally don't have to worry about NSUserDefaults it will store changes whenever there is time, if you need to make sure a changes has been written to disk call - (BOOL) synchronise, it will return YES if the defaults were correctly written to disc.

See the NSUserDefaults reference page at Apple

夜清冷一曲。 2024-10-02 09:29:37

通常,同步过程是异步的,通常人们不关心它何时保存到文件系统中。但如果你想控制,你可以调用 syncrhonize 方法 同步调用它。

问题是,NSUserDefaults 会将您的数据保存到内存中,然后在一段时间后,它将保存到文件系统中。但是,您始终处理接口级别,因此内存中或文件系统中的数据没有任何区别

Usually, the synchronize process is asynchronous and normally people don't care about when it is saved into file system. But if you want to control you can call syncrhonize method to call it synchronously.

The thing is that, the NSUserDefaults will save your data to memory, and then in some time, it will save into the file system. However, you always deal with the interface level, so the data in memory or in file system doesn't have any difference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文