iOS Developer Library

Developer

Foundation Framework Reference NSCoding Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSCoding

The NSCoding protocol declares the two methods that a class must implement so that instances of that class can be encoded and decoded. This capability provides the basis for archiving (where objects and other structures are stored on disk) and distribution (where objects are copied to different address spaces). More...

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


import Foundation @import Foundation;

Availability


Available in iOS 2.0 and later.
  • Returns an object initialized from data in a given unarchiver. (required)

    Declaration

    Swift

    init(coder decoder: NSCoder)

    Objective-C

    - (id)initWithCoder:(NSCoder *)decoder

    Parameters

    decoder

    An unarchiver object.

    Return Value

    self, initialized using the data in decoder.

    Discussion

    You must return self from initWithCoder:. If you have an advanced need that requires substituting a different object after decoding, you can do so in awakeAfterUsingCoder:.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Encodes the receiver using a given archiver. (required)

    Declaration

    Swift

    func encodeWithCoder(_ encoder: NSCoder)

    Objective-C

    - (void)encodeWithCoder:(NSCoder *)encoder

    Parameters

    encoder

    An archiver object.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.