Instance Method

application(_:willEncodeRestorableStateWith:)

Tells your delegate to save any high-level state information at the beginning of the state preservation process.

Declaration

optional func application(_ application: UIApplication, willEncodeRestorableStateWith coder: NSCoder)

Parameters

application

Your singleton app object.

coder

The keyed archiver in which to write any state information.

Discussion

The state preservation system calls this method at the beginning of the preservation process. This is your opportunity to add any app-level information to state information. For example, you might use this method to write version information or the high-level configuration of your app.

Your implementation of this method can encode restorable view and view controller objects that it needs to reference. Encoding a restorable view or view controller writes that object’s restoration identifier to the coder. (That identifier is used during the decode process to locate the new version of the object.) If the view or view controller defines a encodeRestorableState(with:) method, that method is also called at some point so that the object can encode its own state.

Apart from views and view controllers, other objects follow the normal serialization process and must adopt the NSCoding protocol before they can be encoded. Encoding such objects embeds the object’s contents in the archive directly. During the decode process, a new object is created and initialized with the data from the archive.

See Also

Managing App State Restoration

func application(UIApplication, shouldSaveApplicationState: NSCoder)

Asks the delegate whether the app’s state should be preserved.

func application(UIApplication, shouldRestoreApplicationState: NSCoder)

Asks the delegate whether the app’s saved state information should be restored.

func application(UIApplication, didDecodeRestorableStateWith: NSCoder)

Tells your delegate to restore any high-level state information as part of the state restoration process.