Archives and Serialization

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

Topics

First Steps

Encoding and Decoding Custom Types

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

typealias Codable

A type that can convert itself into and out of an external representation.

Beta
protocol NSCoding

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

protocol NSSecureCoding

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

JSON

Using JSON with Custom Types

Demonstrates approaches for encoding and decoding different kinds of JSON in Swift.

class JSONEncoder

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

class JSONDecoder

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

class JSONSerialization

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

Property Lists

class PropertyListEncoder

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

class PropertyListDecoder

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

class PropertyListSerialization

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

Keyed Archivers

class NSKeyedArchiver

A coder that stores an object's data to an archive referenced by keys.

protocol NSKeyedArchiverDelegate

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

class NSKeyedUnarchiver

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

protocol NSKeyedUnarchiverDelegate

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

class NSCoder

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

Deprecated

class NSArchiver

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

Deprecated
class NSUnarchiver

A decoder that restores data from an archive.

Deprecated

See Also

Files and Data Persistence

File System

Create, read, write, and examine files and folders in the file system.

Preferences

Persistently store domain-scoped pieces of information used to configure your app.

Spotlight

Search for files and other items on the local device, and index your app's content for searching.

iCloud

Manage files and key-value data that are automatically synchronized among a user's iCloud devices.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software