---
title: "archivedData(withRootObject:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsarchiver/archiveddata(withrootobject:)"
---

# archivedData(withRootObject:)

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

## Declaration

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

## Parameters

- `rootObject`: The root object of the object graph to archive.

## Return Value

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

## Discussion

Discussion This method invokes init(forWritingWith:) and encodeRootObject(_:) to create a temporary archiver that encodes the object graph.

## See Also

### Related Documentation

- [init(forWritingWith:)](foundation/nsarchiver/init(forwritingwith:).md)

### Archiving data

- [archiveRootObject(_:toFile:)](foundation/nsarchiver/archiverootobject(_:tofile:).md)
- [encodeRootObject(_:)](foundation/nsarchiver/encoderootobject(_:).md)
- [encodeConditionalObject(_:)](foundation/nsarchiver/encodeconditionalobject(_:).md)
