Instance Method

encode(_:)

Encodes an object.

Declaration

func encode(_ object: Any?)

Discussion

NSCoder’s implementation simply invokes encodeValue(ofObjCType:at:) to encode object. Subclasses can override this method to encode a reference to object instead of object itself. For example, NSArchiver detects duplicate objects and encodes a reference to the original object rather than encode the same object twice.

This method must be matched by a subsequent decodeObject() message.

See Also

Encoding General Data

func encodeArray(ofObjCType: UnsafePointer<Int8>, count: Int, at: UnsafeRawPointer)

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

func encode(Bool, forKey: String)

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

func encodeBycopyObject(Any?)

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

func encodeByrefObject(Any?)

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

func encodeBytes(UnsafeRawPointer?, length: Int)

Encodes a buffer of data of an unspecified type.

func encodeBytes(UnsafePointer<UInt8>?, length: Int, forKey: String)

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

func encodeConditionalObject(Any?)

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

func encodeConditionalObject(Any?, forKey: String)

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)

Encodes a given data object.

func encode(Double, forKey: String)

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

func encode(Float, forKey: String)

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

func encodeCInt(Int32, forKey: String)

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

func encode(Int, forKey: String)

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

func encode(Int32, forKey: String)

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

func encode(Int64, forKey: String)

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

func encode(Any?, forKey: String)

Encodes an object and associates it with the string key.

func encode(NSPoint)

Encodes a point.

func encode(NSPoint, forKey: String)

Encodes a point and associates it with the string key.

func encodePropertyList(Any)

Encodes a property list.

func encode(NSRect)

Encodes a rectangle structure.

func encode(NSRect, forKey: String)

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

func encodeRootObject(Any)

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

func encode(NSSize)

Encodes a size structure.

func encode(NSSize, forKey: String)

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

func encodeValue(ofObjCType: UnsafePointer<Int8>, at: UnsafeRawPointer)

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