Add completion block when saving to user defaults

Balázs Vincze

I am saving data to the user defaults using NSKeyedArchiver. Sometimes, there might be a small delay before the data is actually archived and saved, after calling my method to save the data.

I am reading this data from a Today's extension, and would like to update the extension once the data has been saved.

How can I add a completion block or something similar, to get notified when saving the data has completed?

barryjones

Isn't NSKeyedArchiver a synchronous operation ? You shouldn't have to wait for it to complete. It will proceed to the next line only after the data is completely archived.

NSKeyedArchiver.archiveRootObject(books, toFile: "/path/to/archive")

Worst case, you can use callbacks to do something after the archive operation is complete.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related