简体   繁体   中英

Add completion block when saving to user defaults

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM