<!--
{
  "documentType" : "article",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/archives-and-serialization",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Archives and Serialization"
}
-->

# Archives and Serialization

Convert objects and values to and from property list, JSON, and other flat binary representations.

## Discussion

Use these APIs to convert your app’s in-memory types to representations suitable for serialization over I/O and network interfaces or to long-term storage.

In Swift, the standard library defines the <doc://com.apple.documentation/documentation/Swift/Encodable>, <doc://com.apple.documentation/documentation/Swift/Decodable>, and <doc://com.apple.documentation/documentation/Swift/Codable> types, along with <doc://com.apple.documentation/documentation/Swift/Encoder> and <doc://com.apple.documentation/documentation/Swift/Decoder> APIs to perform encoding and decoding, as described in <doc://com.apple.documentation/documentation/Swift/encoding-decoding-and-serialization>. Foundation extends this with the [`EncodableWithConfiguration`](/documentation/Foundation/EncodableWithConfiguration) and [`DecodableWithConfiguration`](/documentation/Foundation/DecodableWithConfiguration) protocols, used for types that require additional static information to encode and decode, such as [`AttributedString`](/documentation/Foundation/AttributedString).

In Objective-C, [`NSCoding`](/documentation/Foundation/NSCoding) defines a protocol for encoding and decoding objects. When adding serialization to your own types, you should also adopt [`NSSecureCoding`](/documentation/Foundation/NSSecureCoding). This protocol adds protection against security vulnerabilities introduced by instantiating arbitrary objects as part of the decoding process.

Many system frameworks use these types. When working with external systems, such as URL endpoints, use the JSON and XML APIs to serialize your app’s types to standard formats.

## Topics

### Adopting Codability

[Encoding and Decoding Custom Types](/documentation/Foundation/encoding-and-decoding-custom-types)

Make your data types encodable and decodable for compatibility with external representations such as JSON.

  <doc://com.apple.documentation/documentation/Swift/Codable>

[`NSCoding`](/documentation/Foundation/NSCoding)

A protocol that enables an object to be encoded and decoded for archiving and distribution.

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

A protocol that enables encoding and decoding in a manner that is robust against object substitution attacks.

### Serializing Arbitrary Payloads

[`CodableWithConfiguration`](/documentation/Foundation/CodableWithConfiguration)

A type that can convert itself into and out of an external representation with the help of a configuration that handles encoding contained types.

[`CodableConfiguration`](/documentation/Foundation/CodableConfiguration)

A property wrapper that makes a type codable, by supplying a configuration that provides additional information for serialization.

[`DecodableWithConfiguration`](/documentation/Foundation/DecodableWithConfiguration)

A protocol for types that support decoding when supplied with an additional configuration type.

[`DecodingConfigurationProviding`](/documentation/Foundation/DecodingConfigurationProviding)

A protocol whose conformers provide a configuration instance to help decode types that don’t support encoding by themselves.

[`EncodableWithConfiguration`](/documentation/Foundation/EncodableWithConfiguration)

A protocol for types that support encoding when supplied with an additional configuration type.

[`EncodingConfigurationProviding`](/documentation/Foundation/EncodingConfigurationProviding)

A protocol whose conformers provide a configuration instance to help encode types that don’t support encoding by themselves.

### JSON

[Using JSON with custom types](/documentation/Foundation/using-json-with-custom-types)

Encode and decode JSON data, regardless of its structure, using Swift’s JSON support.

[`JSONEncoder`](/documentation/Foundation/JSONEncoder)

An object that encodes instances of a data type as JSON objects.

[`JSONDecoder`](/documentation/Foundation/JSONDecoder)

An object that decodes instances of a data type from JSON objects.

[`JSONSerialization`](/documentation/Foundation/JSONSerialization)

An object that converts between JSON and the equivalent Foundation objects.

### Property Lists

[`PropertyListEncoder`](/documentation/Foundation/PropertyListEncoder)

An object that encodes instances of data types to a property list.

[`PropertyListDecoder`](/documentation/Foundation/PropertyListDecoder)

An object that decodes instances of data types from a property list.

[`PropertyListSerialization`](/documentation/Foundation/PropertyListSerialization)

An object that converts between a property list and one of several serialized representations.

### XML

[XML Processing and Modeling](/documentation/Foundation/xml-processing-and-modeling)

Parse XML documents.

### Keyed Archivers

[`NSKeyedArchiver`](/documentation/Foundation/NSKeyedArchiver)

An encoder that stores an object’s data to an archive referenced by keys.

[`NSKeyedArchiverDelegate`](/documentation/Foundation/NSKeyedArchiverDelegate)

The optional methods implemented by the delegate of a keyed archiver.

[`NSKeyedUnarchiver`](/documentation/Foundation/NSKeyedUnarchiver)

A decoder that restores data from an archive referenced by keys.

[`NSKeyedUnarchiverDelegate`](/documentation/Foundation/NSKeyedUnarchiverDelegate)

The optional methods implemented by the delegate of a keyed unarchiver.

[`NSCoder`](/documentation/Foundation/NSCoder)

An abstract class that serves as the basis for objects that enable archiving and distribution of other objects.

[`NSSecureUnarchiveFromDataTransformer`](/documentation/Foundation/NSSecureUnarchiveFromDataTransformer)

A value transformer that converts data to and from classes that support secure coding.

### Deprecated

[`NSArchiver`](/documentation/Foundation/NSArchiver)

A coder that stores an object’s data to an archive.

[`NSUnarchiver`](/documentation/Foundation/NSUnarchiver)

A decoder that restores data from an archive.

[`NXReadNSObjectFromCoder`](/documentation/Foundation/NXReadNSObjectFromCoder)

Returns the next object from the coder.



---

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)