---
title: "encodeRestorableState(with:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uistaterestoring/encoderestorablestate(with:)"
---

# encodeRestorableState(with:)

Encodes state-related information for the object.

## Declaration

```swift
optional func encodeRestorableState(with coder: NSCoder)
```

## Parameters

- `coder`: The coder object to use to encode the state of the object.

## Mentioned in

About the UI preservation process

## Discussion

Discussion You can implement this method for any object that has state information you want to preserve. When deciding what data to save, write the smallest amount of data needed to restore the object to its current configuration. The information you save should be data that you could not easily recreate. You can also save references to other objects, such as the view controller that was using the object. important: This method is not a substitute for saving your app’s data structures persistently to disk. You should continue to save your app’s actual data to iCloud or the local file system using existing techniques. This method is intended only for saving configuration state or other information related to your app’s user interface. You should consider any data you write to the coder as purgeable and be prepared for it to be unavailable during subsequent launches. It is strongly recommended that you call super at some point during your implementation to give parent classes an opportunity to save information too.

## See Also

### Encoding and decoding the object

- [decodeRestorableState(with:)](uikit/uistaterestoring/decoderestorablestate(with:).md)
- [applicationFinishedRestoringState()](uikit/uistaterestoring/applicationfinishedrestoringstate().md)
