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

# archivedData(withRootObject:)

Returns a data object that contains the encoded form of the object graph formed by the given root object.

```
class func archivedData(withRootObject rootObject: Any) -> Data
```

## Parameters

`rootObject`

The root of the object graph to archive.

## Return Value

An `NSData` object containing the encoded form of the object graph whose root object is `rootObject`. The format of the archive is [`PropertyListSerialization.PropertyListFormat.binary`](/documentation/Foundation/PropertyListSerialization/PropertyListFormat/binary).

## Discussion

---

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)