<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCoder",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCoder"
  },
  "title" : "NSCoder"
}
-->

# NSCoder

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

```
class NSCoder
```

## Overview

[`NSCoder`](/documentation/Foundation/NSCoder) declares the interface used by concrete subclasses to transfer objects and other values between memory and some other format. This capability provides the basis for archiving (storing objects and data on disk) and distribution (copying objects and data items between different processes or threads). The concrete subclasses provided by Foundation for these purposes are [`NSArchiver`](/documentation/Foundation/NSArchiver), [`NSUnarchiver`](/documentation/Foundation/NSUnarchiver), [`NSKeyedArchiver`](/documentation/Foundation/NSKeyedArchiver), [`NSKeyedUnarchiver`](/documentation/Foundation/NSKeyedUnarchiver), and [`NSPortCoder`](/documentation/Foundation/NSPortCoder). Concrete subclasses of [`NSCoder`](/documentation/Foundation/NSCoder) are “coder classes”, and instances of these classes are “coder objects” (or simply “coders”). A coder that can only encode values is an “encoder”, and one that can only decode values is a “decoder”.

[`NSCoder`](/documentation/Foundation/NSCoder) operates on objects, scalars, C arrays, structures, strings, and on pointers to these types. It doesn’t handle types whose implementation varies across platforms, such as `union`, `void *`, function pointers, and long chains of pointers. A coder stores object type information along with the data, so an object decoded from a stream of bytes is normally of the same class as the object that was originally encoded into the stream. An object can change its class when encoded, however; this is described in [Archives and Serializations Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Archiving/Archiving.html#//apple_ref/doc/uid/10000047i).

The AVFoundation framework adds methods to the [`NSCoder`](/documentation/Foundation/NSCoder) class to make it easier to create archives including Core Media time structures, and extract Core Media time structure from archives.

### Subclassing Notes

For details of how to create a subclass of `NSCoder`, see [Subclassing NSCoder](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Archiving/Articles/subclassing.html#//apple_ref/doc/uid/20000951) in [Archives and Serializations Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Archiving/Archiving.html#//apple_ref/doc/uid/10000047i).

## Topics

### Inspecting a Coder

[`var allowsKeyedCoding: Bool`](/documentation/Foundation/NSCoder/allowsKeyedCoding)

A Boolean value that indicates whether the receiver supports keyed coding of objects.

[`func containsValue(forKey: String) -> Bool`](/documentation/Foundation/NSCoder/containsValue(forKey:))

Returns a Boolean value that indicates whether an encoded value is available for a string.

[`var decodingFailurePolicy: NSCoder.DecodingFailurePolicy`](/documentation/Foundation/NSCoder/decodingFailurePolicy-swift.property)

The action the coder should take when decoding fails.

[`enum DecodingFailurePolicy`](/documentation/Foundation/NSCoder/DecodingFailurePolicy-swift.enum)

Policies describing the action the coder should take when encountering decode failures.

### Encoding General Data

[`func encodeArray(ofObjCType: UnsafePointer<CChar>, count: Int, at: UnsafeRawPointer)`](/documentation/Foundation/NSCoder/encodeArray(ofObjCType:count:at:))

Encodes an array of the given Objective-C type, provided the number of items and a pointer.

[`func encode(Bool, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-7o6mu)

Encodes a Boolean value and associates it with the string `key`.

[`func encodeBycopyObject(Any?)`](/documentation/Foundation/NSCoder/encodeBycopyObject(_:))

An encoding method for subclasses to override such that it creates a copy, rather than a proxy, when decoded.

[`func encodeByrefObject(Any?)`](/documentation/Foundation/NSCoder/encodeByrefObject(_:))

An encoding method for subclasses to override such that it creates a proxy, rather than a copy, when decoded.

[`func encodeBytes(UnsafeRawPointer?, length: Int)`](/documentation/Foundation/NSCoder/encodeBytes(_:length:))

Encodes a buffer of data of an unspecified type.

[`func encodeBytes(UnsafePointer<UInt8>?, length: Int, forKey: String)`](/documentation/Foundation/NSCoder/encodeBytes(_:length:forKey:))

Encodes a buffer of data, given its length and a pointer, and associates it with a string key.

[`func encodeConditionalObject(Any?)`](/documentation/Foundation/NSCoder/encodeConditionalObject(_:))

An encoding method for subclasses to override to conditionally encode an object, preserving common references to it.

[`func encodeConditionalObject(Any?, forKey: String)`](/documentation/Foundation/NSCoder/encodeConditionalObject(_:forKey:))

An encoding method for subclasses to override to conditionally encode an object, preserving common references to it, only if it has been unconditionally encoded.

[`func encode(Data)`](/documentation/Foundation/NSCoder/encode(_:)-1qd1e)

Encodes a given data object.

[`func encode(Double, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-9xiiu)

Encodes a double-precision floating point value and associates it with the string key.

[`func encode(Float, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-84cez)

Encodes a floating point value and associates it with the string key.

[`func encodeCInt(Int32, forKey: String)`](/documentation/Foundation/NSCoder/encodeCInt(_:forKey:))

Encodes a C integer value and associates it with the string key.

[`func encode(Int, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2dprz)

Encodes an integer value and associates it with the string key.

[`func encode(Int32, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-5sk4z)

Encodes a 32-bit integer value and associates it with the string key.

[`func encode(Int64, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-dixg)

Encodes a 64-bit integer value and associates it with the string key.

[`- (void) encodeNXObject:(id) object;`](/documentation/Foundation/NSCoder/encodeNXObject:)

Encodes an old-style object onto the coder.

[`func encode(Any?)`](/documentation/Foundation/NSCoder/encode(_:)-9648d)

Encodes an object.

[`func encode(Any?, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-1mlmu)

Encodes an object and associates it with the string key.

[`func encode(NSPoint)`](/documentation/Foundation/NSCoder/encode(_:)-75jv4)

Encodes a point.

[`func encode(NSPoint, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-27lif)

Encodes a point and associates it with the string key.

[`func encodePropertyList(Any)`](/documentation/Foundation/NSCoder/encodePropertyList(_:))

Encodes a property list.

[`func encode(NSRect)`](/documentation/Foundation/NSCoder/encode(_:)-3c1wz)

Encodes a rectangle structure.

[`func encode(NSRect, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2knxx)

Encodes a rectangle structure and associates it with the string key.

[`func encodeRootObject(Any)`](/documentation/Foundation/NSCoder/encodeRootObject(_:))

An encoding method for subclasses to override to encode an interconnected group of objects, starting with the provided root object.

[`func encode(NSSize)`](/documentation/Foundation/NSCoder/encode(_:)-82i7c)

Encodes a size structure.

[`func encode(NSSize, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-9imtu)

Encodes a size structure and associates it with the given string key.

[`func encodeValue(ofObjCType: UnsafePointer<CChar>, at: UnsafeRawPointer)`](/documentation/Foundation/NSCoder/encodeValue(ofObjCType:at:))

Encodes a value of the given type at the given address.

[`- (void) encodeValuesOfObjCTypes:(const char *) types;`](/documentation/Foundation/NSCoder/encodeValuesOfObjCTypes:)

Encodes a series of values of potentially differing Objective-C types.

### Encoding Geometry-Based Data

[`func encode(CGAffineTransform, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-29jyx)

Encodes an affine transform and associates it with the specified key in the receiver’s archive.

[`func encode(CGPoint, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-7z9kc)

Encodes a point and associates it with the specified key in the receiver’s archive.

[`func encode(CGRect, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-10qhm)

Encodes a rectangle and associates it with the specified key in the receiver’s archive.

[`func encode(CGSize, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-6wq3n)

Encodes size information and associates it with the specified key in the coder’s archive.

[`func encode(CGVector, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-26fxa)

Encodes vector data and associates it with the specified key in the coder’s archive.

[`func encode(NSDirectionalEdgeInsets, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-7oo2n)

Encodes directional edge inset data and associates it with the specified key in the coder’s archive.

[`func encode(UIEdgeInsets, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-44zsc)

Encodes edge inset data and associates it with the specified key in the coder’s archive.

[`func encode(UIOffset, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-9d1qy)

Encodes offset data and associates it with the specified key in the coder’s archive.

### Encoding Core Media Time Structures

[`func encode(CMTime, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-6wbby)

Encodes a given Core Media time structure and associates it with a specified key.

[`func encode(CMTimeRange, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-46lo8)

Encodes a given Core Media time range structure and associates it with a specified key.

[`func encode(CMTimeMapping, forKey: String)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-8tefb)

Encodes a given Core Media time mapping structure and associates it with a specified key.

### Secure Coding

[`var requiresSecureCoding: Bool`](/documentation/Foundation/NSCoder/requiresSecureCoding)

Indicates whether the archiver requires all archived classes to resist object substitution attacks.

[`var allowedClasses: Set<AnyHashable>?`](/documentation/Foundation/NSCoder/allowedClasses)

The set of coded classes allowed for secure coding.

### Decoding Top-Level Objects

[`func decodeObject<DecodedObjectType>(of: DecodedObjectType.Type, forKey: String) -> DecodedObjectType?`](/documentation/Foundation/NSCoder/decodeObject(of:forKey:)-7tmft)

Decode an object as an expected type, failing if the archived type doesn’t match.

[`func decodeObject(of: [AnyClass]?, forKey: String) -> Any?`](/documentation/Foundation/NSCoder/decodeObject(of:forKey:)-roif)

Decode an object as one of several expected types, failing if the archived type doesn’t match any of the types.

[`func decodeTopLevelObject() throws -> Any?`](/documentation/Foundation/NSCoder/decodeTopLevelObject())

Decodes a previously-encoded object.

[`func decodeTopLevelObject(forKey: String) throws -> Any?`](/documentation/Foundation/NSCoder/decodeTopLevelObject(forKey:))

Decodes the previously-encoded object associated by a key.

[`func decodeTopLevelObject<DecodedObjectType>(of: DecodedObjectType.Type, forKey: String) throws -> DecodedObjectType?`](/documentation/Foundation/NSCoder/decodeTopLevelObject(of:forKey:)-3w6pd)

Decode an object as one of several expected types, failing if the archived type does not match.

[`func decodeTopLevelObject(of: [AnyClass]?, forKey: String) throws -> Any?`](/documentation/Foundation/NSCoder/decodeTopLevelObject(of:forKey:)-5lnnn)

Decode an object as one of several expected types, failing if the archived type does not match.

[`- (id) decodeTopLevelObjectOfClass:(Class) aClass forKey:(NSString *) key error:(NSError **) error;`](/documentation/Foundation/NSCoder/decodeTopLevelObjectOfClass:forKey:error:)

Decode an object as an expected type, failing if the archived type does not match.

[`- (id) decodeTopLevelObjectOfClasses:(NSSet<Class> *) classes forKey:(NSString *) key error:(NSError **) error;`](/documentation/Foundation/NSCoder/decodeTopLevelObjectOfClasses:forKey:error:)

Decode an object as one of several expected types, failing if the archived type does not match.

[`- (id) decodeTopLevelObjectAndReturnError:(NSError **) error;`](/documentation/Foundation/NSCoder/decodeTopLevelObjectAndReturnError:)

Decodes a previously-encoded object, populating an error if decoding fails.

[`- (id) decodeTopLevelObjectForKey:(NSString *) key error:(NSError **) error;`](/documentation/Foundation/NSCoder/decodeTopLevelObjectForKey:error:)

Decodes the previously-encoded object associated by a key, populating an error if decoding fails.

### Decoding General Data

[`func decodeArray(ofObjCType: UnsafePointer<CChar>, count: Int, at: UnsafeMutableRawPointer)`](/documentation/Foundation/NSCoder/decodeArray(ofObjCType:count:at:))

Decodes an array of `count` items, whose Objective-C type is given by `itemType`.

[`func decodeBool(forKey: String) -> Bool`](/documentation/Foundation/NSCoder/decodeBool(forKey:))

Decodes and returns a boolean value that was previously encoded with [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-7o6mu) and associated with the string `key`.

[`func decodeBytes(forKey: String, returnedLength: UnsafeMutablePointer<Int>?) -> UnsafePointer<UInt8>?`](/documentation/Foundation/NSCoder/decodeBytes(forKey:returnedLength:))

Decodes a buffer of data that was previously encoded with [`encodeBytes(_:length:forKey:)`](/documentation/Foundation/NSCoder/encodeBytes(_:length:forKey:)) and associated with the string `key`.

[`func decodeBytes(withReturnedLength: UnsafeMutablePointer<Int>) -> UnsafeMutableRawPointer?`](/documentation/Foundation/NSCoder/decodeBytes(withReturnedLength:))

Decodes a buffer of data whose types are unspecified.

[`func decodeData() -> Data?`](/documentation/Foundation/NSCoder/decodeData())

Decodes and returns an `NSData` object that was previously encoded with [`encode(_:)`](/documentation/Foundation/NSCoder/encode(_:)-1qd1e). Subclasses must override this method.

[`func decodeDouble(forKey: String) -> Double`](/documentation/Foundation/NSCoder/decodeDouble(forKey:))

Decodes and returns a double value that was previously encoded with either [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-84cez) or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-9xiiu) and associated with the string `key`.

[`func decodeFloat(forKey: String) -> Float`](/documentation/Foundation/NSCoder/decodeFloat(forKey:))

Decodes and returns a float value that was previously encoded with [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-84cez) or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-9xiiu) and associated with the string `key`.

[`func decodeCInt(forKey: String) -> Int32`](/documentation/Foundation/NSCoder/decodeCInt(forKey:))

Decodes and returns an int value that was previously encoded with [`encodeCInt(_:forKey:)`](/documentation/Foundation/NSCoder/encodeCInt(_:forKey:)), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2dprz), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-5sk4z), or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-dixg) and associated with the string `key`.

[`func decodeInteger(forKey: String) -> Int`](/documentation/Foundation/NSCoder/decodeInteger(forKey:))

Decodes and returns an NSInteger value that was previously encoded with [`encodeCInt(_:forKey:)`](/documentation/Foundation/NSCoder/encodeCInt(_:forKey:)), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2dprz), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-5sk4z), or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-dixg) and associated with the string `key`.

[`func decodeInt32(forKey: String) -> Int32`](/documentation/Foundation/NSCoder/decodeInt32(forKey:))

Decodes and returns a 32-bit integer value that was previously encoded with [`encodeCInt(_:forKey:)`](/documentation/Foundation/NSCoder/encodeCInt(_:forKey:)), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2dprz), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-5sk4z), or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-dixg) and associated with the string `key`.

[`func decodeInt64(forKey: String) -> Int64`](/documentation/Foundation/NSCoder/decodeInt64(forKey:))

Decodes and returns a 64-bit integer value that was previously encoded with [`encodeCInt(_:forKey:)`](/documentation/Foundation/NSCoder/encodeCInt(_:forKey:)), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2dprz), [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-5sk4z), or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-dixg) and associated with the string `key`.

[`- (id) decodeNXObject;`](/documentation/Foundation/NSCoder/decodeNXObject)

Decodes an object previously written with [`encodeNXObject:`](/documentation/Foundation/NSCoder/encodeNXObject:).

[`func decodeObject() -> Any?`](/documentation/Foundation/NSCoder/decodeObject())

Decodes and returns an object that was previously encoded with any of the `encode…Object` methods.

[`func decodeObject(forKey: String) -> Any?`](/documentation/Foundation/NSCoder/decodeObject(forKey:))

Decodes and returns a previously-encoded object that was previously encoded with [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-1mlmu) or [`encodeConditionalObject(_:forKey:)`](/documentation/Foundation/NSCoder/encodeConditionalObject(_:forKey:)) and associated with the string `key`.

[`func decodePoint() -> NSPoint`](/documentation/Foundation/NSCoder/decodePoint())

Decodes and returns an NSPoint structure that was previously encoded with [`encode(_:)`](/documentation/Foundation/NSCoder/encode(_:)-75jv4).

[`func decodePoint(forKey: String) -> NSPoint`](/documentation/Foundation/NSCoder/decodePoint(forKey:))

Decodes and returns an NSPoint structure that was previously encoded with [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-27lif).

[`func decodePropertyList() -> Any?`](/documentation/Foundation/NSCoder/decodePropertyList())

Decodes a property list that was previously encoded with [`encodePropertyList(_:)`](/documentation/Foundation/NSCoder/encodePropertyList(_:)).

[`func decodeRect() -> NSRect`](/documentation/Foundation/NSCoder/decodeRect())

Decodes and returns an NSRect structure that was previously encoded with [`encode(_:)`](/documentation/Foundation/NSCoder/encode(_:)-3c1wz).

[`func decodeRect(forKey: String) -> NSRect`](/documentation/Foundation/NSCoder/decodeRect(forKey:))

Decodes and returns an NSRect structure that was previously encoded with [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-2knxx).

[`func decodeSize() -> NSSize`](/documentation/Foundation/NSCoder/decodeSize())

Decodes and returns an NSSize structure that was previously encoded with [`encode(_:)`](/documentation/Foundation/NSCoder/encode(_:)-82i7c).

[`func decodeSize(forKey: String) -> NSSize`](/documentation/Foundation/NSCoder/decodeSize(forKey:))

Decodes and returns an NSSize structure that was previously encoded with [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-9imtu).

[`func decodeValue(ofObjCType: UnsafePointer<CChar>, at: UnsafeMutableRawPointer)`](/documentation/Foundation/NSCoder/decodeValue(ofObjCType:at:))

Decodes a single value, whose Objective-C type is given by `valueType`.

[`func decodeValue(ofObjCType: UnsafePointer<CChar>, at: UnsafeMutableRawPointer, size: Int)`](/documentation/Foundation/NSCoder/decodeValue(ofObjCType:at:size:))

Decodes a single value of a known type from the specified data buffer.

[`- (void) decodeValuesOfObjCTypes:(const char *) types;`](/documentation/Foundation/NSCoder/decodeValuesOfObjCTypes:)

Decodes a series of potentially different Objective-C types.

[`- (id) decodeObjectOfClass:(Class) aClass forKey:(NSString *) key;`](/documentation/Foundation/NSCoder/decodeObjectOfClass:forKey:)

Decodes an object for the key, restricted to the specified class.

[`- (id) decodeObjectOfClasses:(NSSet<Class> *) classes forKey:(NSString *) key;`](/documentation/Foundation/NSCoder/decodeObjectOfClasses:forKey:)

Decodes an object for the key, restricted to the specified classes.

[`func decodePropertyList(forKey: String) -> Any?`](/documentation/Foundation/NSCoder/decodePropertyList(forKey:))

Returns a decoded property list for the specified key.

### Decoding Color Struct Data

[`- (NSColor *) decodeNXColor;`](/documentation/Foundation/NSCoder/decodeNXColor)

Decodes a color structure from NEXTSTEP Release 3 or earlier.

### Decoding Geometry-Based Data

[`func decodeCGAffineTransform(forKey: String) -> CGAffineTransform`](/documentation/Foundation/NSCoder/decodeCGAffineTransform(forKey:))

Decodes and returns the Core Graphics affine transform structure associated with the specified key in the coder’s archive.

[`func decodeCGPoint(forKey: String) -> CGPoint`](/documentation/Foundation/NSCoder/decodeCGPoint(forKey:))

Decodes and returns the Core Graphics point structure associated with the specified key in the coder’s archive.

[`func decodeCGRect(forKey: String) -> CGRect`](/documentation/Foundation/NSCoder/decodeCGRect(forKey:))

Decodes and returns the Core Graphics rectangle structure associated with the specified key in the coder’s archive.

[`func decodeCGSize(forKey: String) -> CGSize`](/documentation/Foundation/NSCoder/decodeCGSize(forKey:))

Decodes and returns the Core Graphics size structure associated with the specified key in the coder’s archive.

[`func decodeCGVector(forKey: String) -> CGVector`](/documentation/Foundation/NSCoder/decodeCGVector(forKey:))

Decodes and returns the Core Graphics vector data associated with the specified key in the coder’s archive.

[`func decodeDirectionalEdgeInsets(forKey: String) -> NSDirectionalEdgeInsets`](/documentation/Foundation/NSCoder/decodeDirectionalEdgeInsets(forKey:))

Decodes and returns the UIKit directional edge insets structure associated with the specified key in the coder’s archive.

[`func decodeUIEdgeInsets(forKey: String) -> UIEdgeInsets`](/documentation/Foundation/NSCoder/decodeUIEdgeInsets(forKey:))

Decodes and returns the UIKit edge insets structure associated with the specified key in the coder’s archive.

[`func decodeUIOffset(forKey: String) -> UIOffset`](/documentation/Foundation/NSCoder/decodeUIOffset(forKey:))

Decodes and returns the UIKit offset structure associated with the specified key in the coder’s archive.

### Decoding Core Media Time Structures

[`func decodeTime(forKey: String) -> CMTime`](/documentation/Foundation/NSCoder/decodeTime(forKey:))

Returns the Core Media time structure associated with a given key.

[`func decodeTimeRange(forKey: String) -> CMTimeRange`](/documentation/Foundation/NSCoder/decodeTimeRange(forKey:))

Returns the Core Media time range structure associated with a given key.

[`func decodeTimeMapping(forKey: String) -> CMTimeMapping`](/documentation/Foundation/NSCoder/decodeTimeMapping(forKey:))

Returns the Core Media time mapping structure associated with a given key.

### Managing Decode Errors

[`func failWithError(any Error)`](/documentation/Foundation/NSCoder/failWithError(_:))

Signals to this coder that the decode operation has failed.

[`var error: (any Error)?`](/documentation/Foundation/NSCoder/error)

An error in the top-level encode.

### Getting Version Information

[`var systemVersion: UInt32`](/documentation/Foundation/NSCoder/systemVersion)

The system version in effect for the archive.

[`func version(forClassName: String) -> Int`](/documentation/Foundation/NSCoder/version(forClassName:))

This method is present for historical reasons and is not used with keyed archivers.

### Managing Zones

[`- (NSZone *) objectZone;`](/documentation/Foundation/NSCoder/objectZone)

This method is present for historical reasons and has no effect.

[`- (void) setObjectZone:(NSZone *) zone;`](/documentation/Foundation/NSCoder/setObjectZone:)

This method is present for historical reasons and has no effect.

### Representing Geometric Types as Strings

Convenience methods for creating encodable and decodable types in Objective-C.

[`class func cgAffineTransform(for: String) -> CGAffineTransform`](/documentation/Foundation/NSCoder/cgAffineTransform(for:))

Returns a Core Graphics affine transform structure corresponding to the data in a given string.

[`class func cgPoint(for: String) -> CGPoint`](/documentation/Foundation/NSCoder/cgPoint(for:))

Returns a Core Graphics point structure corresponding to the data in a given string.

[`class func cgRect(for: String) -> CGRect`](/documentation/Foundation/NSCoder/cgRect(for:))

Returns a Core Graphics rectangle structure corresponding to the data in a given string.

[`class func cgSize(for: String) -> CGSize`](/documentation/Foundation/NSCoder/cgSize(for:))

Returns a Core Graphics size structure corresponding to the data in a given string.

[`class func cgVector(for: String) -> CGVector`](/documentation/Foundation/NSCoder/cgVector(for:))

Returns a Core Graphics vector corresponding to the data in a given string.

[`class func nsDirectionalEdgeInsets(for: String) -> NSDirectionalEdgeInsets`](/documentation/Foundation/NSCoder/nsDirectionalEdgeInsets(for:))

Returns a directional edge insets structure based on data in the specified string.

[`class func uiEdgeInsets(for: String) -> UIEdgeInsets`](/documentation/Foundation/NSCoder/uiEdgeInsets(for:))

Returns a UIKit edge insets structure based on the data in the specified string.

[`class func uiOffset(for: String) -> UIOffset`](/documentation/Foundation/NSCoder/uiOffset(for:))

Returns a UIKit offset structure corresponding to the data in a given string.

[`class func string(for: CGRect) -> String`](/documentation/Foundation/NSCoder/string(for:)-4qz0a)

Returns a string formatted to contain the data from a rectangle.

[`class func string(for: CGVector) -> String`](/documentation/Foundation/NSCoder/string(for:)-4omzv)

Returns a string formatted to contain the data from a vector data structure.

[`class func string(for: CGAffineTransform) -> String`](/documentation/Foundation/NSCoder/string(for:)-6yx6n)

Returns a string formatted to contain the data from an affine transform.

[`class func string(for: CGPoint) -> String`](/documentation/Foundation/NSCoder/string(for:)-6ix86)

Returns a string formatted to contain the data from a point.

[`class func string(for: CGSize) -> String`](/documentation/Foundation/NSCoder/string(for:)-2f1xb)

Returns a string formatted to contain the data from a size data structure.

[`class func string(for: NSDirectionalEdgeInsets) -> String`](/documentation/Foundation/NSCoder/string(for:)-hp8b)

Returns a string formatted to contain the data from a directional edge insets structure.

[`class func string(for: UIEdgeInsets) -> String`](/documentation/Foundation/NSCoder/string(for:)-26b4z)

Returns a string formatted to contain the data from an edge insets structure.

[`class func string(for: UIOffset) -> String`](/documentation/Foundation/NSCoder/string(for:)-454dj)

Returns a string formatted to contain the data from an offset structure.

### Representing Geometric Types as Strings

Convenience methods for creating encodable and decodable types in Objective-C.

  <doc://com.apple.documentation/documentation/UIKit/CGAffineTransformFromString>

  <doc://com.apple.documentation/documentation/UIKit/CGPointFromString>

  <doc://com.apple.documentation/documentation/UIKit/CGRectFromString>

  <doc://com.apple.documentation/documentation/UIKit/CGSizeFromString>

  <doc://com.apple.documentation/documentation/UIKit/CGVectorFromString>

  <doc://com.apple.documentation/documentation/UIKit/NSDirectionalEdgeInsetsFromString>

  <doc://com.apple.documentation/documentation/UIKit/UIEdgeInsetsFromString>

  <doc://com.apple.documentation/documentation/UIKit/UIOffsetFromString>

  <doc://com.apple.documentation/documentation/UIKit/NSStringFromCGRect>

  <doc://com.apple.documentation/documentation/UIKit/NSStringFromCGVector>

  <doc://com.apple.documentation/documentation/UIKit/NSStringFromCGAffineTransform>

  <doc://com.apple.documentation/documentation/UIKit/NSStringFromCGPoint>

  <doc://com.apple.documentation/documentation/UIKit/NSStringFromCGSize>

  <doc://com.apple.documentation/documentation/UIKit/NSStringFromDirectionalEdgeInsets>

  <doc://com.apple.documentation/documentation/UIKit/NSStringFromUIEdgeInsets>

  <doc://com.apple.documentation/documentation/UIKit/NSStringFromCGPoint>

  <doc://com.apple.documentation/documentation/UIKit/NSStringFromUIOffset>

### Error Codes

[`var NSCoderErrorMaximum: Int`](/documentation/Foundation/NSCoderErrorMaximum-swift.var)

The end of the range of error codes reserved for coder errors.

[`var NSCoderErrorMinimum: Int`](/documentation/Foundation/NSCoderErrorMinimum-swift.var)

The start of the range of error codes reserved for coder errors.

[`var NSCoderReadCorruptError: Int`](/documentation/Foundation/NSCoderReadCorruptError-swift.var)

Decoding failed due to corrupt data.

[`var NSCoderValueNotFoundError: Int`](/documentation/Foundation/NSCoderValueNotFoundError-swift.var)

The requested data wasn’t found.

[`var NSCoderInvalidValueError: Int`](/documentation/Foundation/NSCoderInvalidValueError-swift.var)

Data wasn’t valid to encode.

[`NSCoderErrorMaximum`](/documentation/Foundation/NSCoderErrorMaximum-c.enum.case)

The end of the range of error codes reserved for coder errors.

[`NSCoderErrorMinimum`](/documentation/Foundation/NSCoderErrorMinimum-c.enum.case)

The start of the range of error codes reserved for coder errors.

[`NSCoderReadCorruptError`](/documentation/Foundation/NSCoderReadCorruptError-c.enum.case)

Decoding failed due to corrupt data.

[`NSCoderValueNotFoundError`](/documentation/Foundation/NSCoderValueNotFoundError-c.enum.case)

The requested data wasn’t found.

### Instance Methods

[`func decodeArrayOfObjects<DecodedObject>(ofClass: DecodedObject.Type, forKey: String) -> [DecodedObject]?`](/documentation/Foundation/NSCoder/decodeArrayOfObjects(ofClass:forKey:))

[`func decodeArrayOfObjects(ofClasses: [AnyClass], forKey: String) -> [Any]?`](/documentation/Foundation/NSCoder/decodeArrayOfObjects(ofClasses:forKey:))

[`func decodeBytes(forKey: String, minimumLength: Int) -> UnsafePointer<UInt8>?`](/documentation/Foundation/NSCoder/decodeBytes(forKey:minimumLength:))

Decode bytes from the decoder for a given key. The length of the bytes must be greater than or equal to the `length` parameter.
If the result exists, but is of insufficient length, then the decoder uses `failWithError` to fail the entire decode operation. The result of that is configurable on a per-NSCoder basis using `NSDecodingFailurePolicy`.

[`func decodeBytes(withMinimumLength: Int) -> UnsafeMutableRawPointer?`](/documentation/Foundation/NSCoder/decodeBytes(withMinimumLength:))

Decode bytes from the decoder. The length of the bytes must be greater than or equal to the `length` parameter.
If the result exists, but is of insufficient length, then the decoder uses `failWithError` to fail the entire decode operation. The result of that is configurable on a per-NSCoder basis using `NSDecodingFailurePolicy`.

[`func decodeDictionary<DecodedKey, DecodedObject>(withKeyClass: DecodedKey.Type, objectClass: DecodedObject.Type, forKey: String) -> [DecodedKey : DecodedObject]?`](/documentation/Foundation/NSCoder/decodeDictionary(withKeyClass:objectClass:forKey:))

[`func decodeDictionary(withKeysOfClasses: [AnyClass], objectsOfClasses: [AnyClass], forKey: String) -> [AnyHashable : Any]?`](/documentation/Foundation/NSCoder/decodeDictionary(withKeysOfClasses:objectsOfClasses:forKey:))

## Relationships

### Conforms To

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Inherited By

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

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

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

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

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

---

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)