Class

NSKeyed​Unarchiver

NSKeyed​Unarchiver, a concrete subclass of NSCoder, defines methods for decoding a set of named objects (and scalar values) from a keyed archive. Such archives are produced by instances of the NSKeyed​Archiver class.

Overview

A keyed archive is encoded as a hierarchy of objects. Each object in the hierarchy serves as a namespace into which other objects are encoded. The objects available for decoding are restricted to those that were encoded within the immediate scope of a particular object. Objects encoded elsewhere in the hierarchy, whether higher than, lower than, or parallel to this particular object, are not accessible. In this way, the keys used by a particular object to encode its instance variables need to be unique only within the scope of that object.

If you invoke one of the decode... methods of this class using a key that does not exist in the archive, a non-positive value is returned. This value varies by decoded type. For example, if a key does not exist in an archive, decode​Bool(for​Key:​) returns false, decode​Int(for​Key:​) returns 0, and decode​Object(for​Key:​) returns nil.

NSKeyed​Unarchiver supports limited type coercion. A value encoded as any type of integer, whether a standard int or an explicit 32-bit or 64-bit integer, can be decoded using any of the integer decode methods. Likewise, a value encoded as a float or double can be decoded as either a float or a double value. If an encoded value is too large to fit within the coerced type, the decoding method throws an NSRange​Exception. Further, when trying to coerce a value to an incompatible type, for example decoding an int as a float, the decoding method throws an NSInvalid​Unarchive​Operation​Exception.

Symbols

Initializing a Keyed Unarchiver

init(for​Reading​With:​ Data)

Initializes the receiver for decoding an archive previously encoded by NSKeyed​Archiver.

Unarchiving Data

class func unarchive​Object(with:​ Data)

Decodes and returns the object graph previously encoded by NSKeyed​Archiver and stored in a given NSData object.

class func unarchive​Object(with​File:​ String)

Decodes and returns the object graph previously encoded by NSKeyed​Archiver written to the file at a given path.

var requires​Secure​Coding:​ Bool

Indicates whether the receiver requires all unarchived classes to conform to NSSecure​Coding.

Decoding Data

func contains​Value(for​Key:​ String)

Returns a Boolean value that indicates whether the archive contains a value for a given key within the current decoding scope.

func decode​Bool(for​Key:​ String)

Decodes a Boolean value associated with a given key.

func decode​Double(for​Key:​ String)

Decodes a double-precision floating-point value associated with a given key.

func decode​Float(for​Key:​ String)

Decodes a single-precision floating-point value associated with a given key.

func decode​Int32(for​Key:​ String)

Decodes a 32-bit integer value associated with a given key.

func decode​Int64(for​Key:​ String)

Decodes a 64-bit integer value associated with a given key.

func decode​Object(for​Key:​ String)

Decodes and returns an object associated with a given key.

func finish​Decoding()

Tells the receiver that you are finished decoding objects.

Managing the Delegate

Managing Class Names

class func set​Class(Any​Class?, for​Class​Name:​ String)

Adds a class translation mapping to NSKeyed​Unarchiver whereby objects encoded with a given class name are decoded as instances of a given class instead.

class func `class`(for​Class​Name:​ String)

Returns the class from which NSKeyed​Unarchiver instantiates an encoded object with a given class name.

func set​Class(Any​Class?, for​Class​Name:​ String)

Adds a class translation mapping to the receiver whereby objects encoded with a given class name are decoded as instances of a given class instead.

func `class`(for​Class​Name:​ String)

Returns the class from which the receiver instantiates an encoded object with a given class name.

Constants

Keyed Unarchiving Exception Names

Names of exceptions that are raised by NSKeyed​Unarchiver if there is a problem extracting an archive.

Relationships

Inherits From