<!--
{
  "availability" : [
    "macOS: 10.13.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSResponder/encodeRestorableState(with:backgroundQueue:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSResponder(im)encodeRestorableStateWithCoder:backgroundQueue:"
  },
  "title" : "encodeRestorableState(with:backgroundQueue:)"
}
-->

# encodeRestorableState(with:backgroundQueue:)

Saves the interface-related state of the responder to a keyed archiver either synchronously or asynchronously on the given operation queue.

```
func encodeRestorableState(with coder: NSCoder, backgroundQueue queue: OperationQueue)
```

## Parameters

`coder`

A thread-safe keyed archiver to write restorable state into.

`queue`

A serial background operation queue to perform asynchronous encoding work on.

## Discussion

Don’t call this method directly. The system calls this method on the main thread. The receiver may synchronously encode state to `coder` or may enqueue asynchronous work to encode additional restorable state using the provided serial background <doc://com.apple.documentation/documentation/Foundation/OperationQueue>, if it can safely access and encode that information. The encoding process finishes when the enqueued operations complete.

If you override this method, call the super implementation.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)