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

# archivedData(withRootObject:requiringSecureCoding:)

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

## Declaration

```swift
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 doc://com.apple.foundation/documentation/Foundation/NSSecureCoding.

## Discussion

Discussion To prevent the possibility of encoding an object that NSKeyedUnarchiver can’t decode, set requiresSecureCoding to true whenever possible. This ensures that all encoded objects conform to 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.

## See Also

### Archiving Data

- [finishEncoding()](foundation/nskeyedarchiver/finishencoding().md)
- [encodedData](foundation/nskeyedarchiver/encodeddata.md)
- [outputFormat](foundation/nskeyedarchiver/outputformat.md)
- [requiresSecureCoding](foundation/nskeyedarchiver/requiressecurecoding.md)
- [archivedData(withRootObject:)](foundation/nskeyedarchiver/archiveddata(withrootobject:).md)
- [archiveRootObject(_:toFile:)](foundation/nskeyedarchiver/archiverootobject(_:tofile:).md)
