保存 NSUserDefaults 完成
我注意到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您通常不必担心
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 returnYES
if the defaults were correctly written to disc.See the NSUserDefaults reference page at Apple
通常,同步过程是异步的,通常人们不关心它何时保存到文件系统中。但如果你想控制,你可以调用 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