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

# archivedData(withRootObject:)

Returns a data object containing the encoded form of the object graph whose root object is given.

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

## Parameters

`rootObject`

The root object of the object graph to archive.

## Return Value

A data object containing the encoded form of the object graph whose root object is `rootObject`.

## Discussion

This method invokes [`init(forWritingWith:)`](/documentation/Foundation/NSArchiver/init(forWritingWith:)) and [`encodeRootObject(_:)`](/documentation/Foundation/NSArchiver/encodeRootObject(_:)) to create a temporary archiver that encodes the object graph.

## See Also

[`-  initForWritingWithMutableData:`](/documentation/Foundation/NSArchiver/init(forWritingWith:))

Returns an archiver, initialized to encode stream and version information into a given mutable data object.



---

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)