<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 4.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSKeyedArchiver/archivedData(withRootObject:requiringSecureCoding:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSKeyedArchiver(cm)archivedDataWithRootObject:requiringSecureCoding:error:"
  },
  "title" : "archivedData(withRootObject:requiringSecureCoding:)"
}
-->

# archivedData(withRootObject:requiringSecureCoding:)

Encodes an object graph with the given root object into a data representation, optionally requiring secure coding.

```
class func archivedData(withRootObject object: Any, requiringSecureCoding requiresSecureCoding: Bool) throws -> Data
```

## Parameters

`object`

The root of the object graph to archive.

`requiresSecureCoding`

A Boolean value indicating whether all encoded objects must conform to [`NSSecureCoding`](/documentation/Foundation/NSSecureCoding).

## Discussion

To prevent the possibility of encoding an object that [`NSKeyedUnarchiver`](/documentation/Foundation/NSKeyedUnarchiver) can’t decode, set `requiresSecureCoding` to true whenever possible. This ensures that all encoded objects conform to [`NSSecureCoding`](/documentation/Foundation/NSSecureCoding).

> Note:
> Enabling secure coding doesn’t change the output format of the archive. This means that you can encode archives with secure coding enabled, and decode them later with secure coding disabled.

---

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)