<!--
{
  "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

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

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

[`containsValue(forKey:)`](/documentation/Foundation/NSCoder/containsValue(forKey:))

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

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

The action the coder should take when decoding fails.

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

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

### Encoding General Data

[`encodeArray(ofObjCType:count:at:)`](/documentation/Foundation/NSCoder/encodeArray(ofObjCType:count:at:))

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

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

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

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

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

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

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

[`encodeBytes(_:length:)`](/documentation/Foundation/NSCoder/encodeBytes(_:length:))

Encodes a buffer of data of an unspecified type.

[`encodeBytes(_:length:forKey:)`](/documentation/Foundation/NSCoder/encodeBytes(_:length:forKey:))

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

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

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

[`encodeConditionalObject(_:forKey:)`](/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.

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

Encodes a given data object.

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

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

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

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

[`encodeCInt(_:forKey:)`](/documentation/Foundation/NSCoder/encodeCInt(_:forKey:))

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

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

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

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

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

[`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-dixg)

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

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

Encodes an old-style object onto the coder.

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

Encodes an object.

[`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-1mlmu)

Encodes an object and associates it with the string key.

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

Encodes a point.

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

Encodes a point and associates it with the string key.

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

Encodes a property list.

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

Encodes a rectangle structure.

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

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

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

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

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

Encodes a size structure.

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

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

[`encodeValue(ofObjCType:at:)`](/documentation/Foundation/NSCoder/encodeValue(ofObjCType:at:))

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

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

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

### Encoding Geometry-Based Data

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[`encode(_:forKey:)`](/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

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

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

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

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

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

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

### Secure Coding

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

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

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

The set of coded classes allowed for secure coding.

### Decoding Top-Level Objects

[`decodeObject(of:forKey:)`](/documentation/Foundation/NSCoder/decodeObject(of:forKey:)-7tmft)

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

[`decodeObject(of:forKey:)`](/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.

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

Decodes a previously-encoded object.

[`decodeTopLevelObject(forKey:)`](/documentation/Foundation/NSCoder/decodeTopLevelObject(forKey:)-7cram)

Decodes the previously-encoded object associated by a key.

[`decodeTopLevelObject(of:forKey:)`](/documentation/Foundation/NSCoder/decodeTopLevelObject(of:forKey:)-3w6pd)

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

[`decodeTopLevelObject(of:forKey:)`](/documentation/Foundation/NSCoder/decodeTopLevelObject(of:forKey:)-5lnnn)

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

[`decodeTopLevelObjectOfClass:forKey:error:`](/documentation/Foundation/NSCoder/decodeTopLevelObjectOfClass:forKey:error:)

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

[`decodeTopLevelObjectOfClasses:forKey:error:`](/documentation/Foundation/NSCoder/decodeTopLevelObjectOfClasses:forKey:error:)

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

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

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

[`decodeTopLevelObjectForKey:error:`](/documentation/Foundation/NSCoder/decodeTopLevelObjectForKey:error:)

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

### Decoding General Data

[`decodeArray(ofObjCType:count:at:)`](/documentation/Foundation/NSCoder/decodeArray(ofObjCType:count:at:))

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

[`decodeBool(forKey:)`](/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`.

[`decodeBytes(forKey:returnedLength:)`](/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`.

[`decodeBytes(withReturnedLength:)`](/documentation/Foundation/NSCoder/decodeBytes(withReturnedLength:))

Decodes a buffer of data whose types are unspecified.

[`decodeData()`](/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.

[`decodeDouble(forKey:)`](/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`.

[`decodeFloat(forKey:)`](/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`.

[`decodeCInt(forKey:)`](/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`.

[`decodeInteger(forKey:)`](/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`.

[`decodeInt32(forKey:)`](/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`.

[`decodeInt64(forKey:)`](/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`.

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

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

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

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

[`decodeObject(forKey:)`](/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`.

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

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

[`decodePoint(forKey:)`](/documentation/Foundation/NSCoder/decodePoint(forKey:))

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

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

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

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

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

[`decodeRect(forKey:)`](/documentation/Foundation/NSCoder/decodeRect(forKey:))

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

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

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

[`decodeSize(forKey:)`](/documentation/Foundation/NSCoder/decodeSize(forKey:))

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

[`decodeValue(ofObjCType:at:)`](/documentation/Foundation/NSCoder/decodeValue(ofObjCType:at:))

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

[`decodeValue(ofObjCType:at:size:)`](/documentation/Foundation/NSCoder/decodeValue(ofObjCType:at:size:))

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

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

Decodes a series of potentially different Objective-C types.

[`decodeObjectOfClass:forKey:`](/documentation/Foundation/NSCoder/decodeObjectOfClass:forKey:)

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

[`decodeObjectOfClasses:forKey:`](/documentation/Foundation/NSCoder/decodeObjectOfClasses:forKey:)

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

[`decodePropertyList(forKey:)`](/documentation/Foundation/NSCoder/decodePropertyList(forKey:))

Returns a decoded property list for the specified key.

### Decoding Color Struct Data

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

Decodes a color structure from NEXTSTEP Release 3 or earlier.

### Decoding Geometry-Based Data

[`decodeCGAffineTransform(forKey:)`](/documentation/Foundation/NSCoder/decodeCGAffineTransform(forKey:))

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

[`decodeCGPoint(forKey:)`](/documentation/Foundation/NSCoder/decodeCGPoint(forKey:))

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

[`decodeCGRect(forKey:)`](/documentation/Foundation/NSCoder/decodeCGRect(forKey:))

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

[`decodeCGSize(forKey:)`](/documentation/Foundation/NSCoder/decodeCGSize(forKey:))

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

[`decodeCGVector(forKey:)`](/documentation/Foundation/NSCoder/decodeCGVector(forKey:))

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

[`decodeDirectionalEdgeInsets(forKey:)`](/documentation/Foundation/NSCoder/decodeDirectionalEdgeInsets(forKey:))

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

[`decodeUIEdgeInsets(forKey:)`](/documentation/Foundation/NSCoder/decodeUIEdgeInsets(forKey:))

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

[`decodeUIOffset(forKey:)`](/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

[`decodeTime(forKey:)`](/documentation/Foundation/NSCoder/decodeTime(forKey:))

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

[`decodeTimeRange(forKey:)`](/documentation/Foundation/NSCoder/decodeTimeRange(forKey:))

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

[`decodeTimeMapping(forKey:)`](/documentation/Foundation/NSCoder/decodeTimeMapping(forKey:))

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

### Managing Decode Errors

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

Signals to this coder that the decode operation has failed.

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

An error in the top-level encode.

### Getting Version Information

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

The system version in effect for the archive.

[`version(forClassName:)`](/documentation/Foundation/NSCoder/version(forClassName:))

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

### Managing Zones

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

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

[`setObjectZone:`](/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.

[`cgAffineTransform(for:)`](/documentation/Foundation/NSCoder/cgAffineTransform(for:))

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

[`cgPoint(for:)`](/documentation/Foundation/NSCoder/cgPoint(for:))

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

[`cgRect(for:)`](/documentation/Foundation/NSCoder/cgRect(for:))

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

[`cgSize(for:)`](/documentation/Foundation/NSCoder/cgSize(for:))

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

[`cgVector(for:)`](/documentation/Foundation/NSCoder/cgVector(for:))

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

[`nsDirectionalEdgeInsets(for:)`](/documentation/Foundation/NSCoder/nsDirectionalEdgeInsets(for:))

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

[`uiEdgeInsets(for:)`](/documentation/Foundation/NSCoder/uiEdgeInsets(for:))

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

[`uiOffset(for:)`](/documentation/Foundation/NSCoder/uiOffset(for:))

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

[`string(for:)`](/documentation/Foundation/NSCoder/string(for:)-4qz0a)

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

[`string(for:)`](/documentation/Foundation/NSCoder/string(for:)-4omzv)

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

[`string(for:)`](/documentation/Foundation/NSCoder/string(for:)-6yx6n)

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

[`string(for:)`](/documentation/Foundation/NSCoder/string(for:)-6ix86)

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

[`string(for:)`](/documentation/Foundation/NSCoder/string(for:)-2f1xb)

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

[`string(for:)`](/documentation/Foundation/NSCoder/string(for:)-hp8b)

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

[`string(for:)`](/documentation/Foundation/NSCoder/string(for:)-26b4z)

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

[`string(for:)`](/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

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

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

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

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

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

Decoding failed due to corrupt data.

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

The requested data wasn’t found.

[`NSCoderInvalidValueError`](/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.



---

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)
