Reputation: 21137
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"];
Upvotes: 1
Views: 1303
Reputation: 9764
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
Upvotes: 2
Reputation: 18741
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
Upvotes: 1