Mac Developer Library

Developer

Foundation Framework Reference NSKeyedUnarchiverDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSKeyedUnarchiverDelegate

Inheritance


Not Applicable

Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.6 and later.

The NSKeyedUnarchiverDelegate protocol defines the optional methods implemented by delegates of NSKeyedUnarchiver objects.

  • Informs the delegate that the class with a given name is not available during decoding.

    Declaration

    Swift

    optional func unarchiver(_ unarchiver: NSKeyedUnarchiver, cannotDecodeObjectOfClassName name: String, originalClasses classNames: [AnyObject]) -> AnyClass

    Objective-C

    - (Class)unarchiver:(NSKeyedUnarchiver *)unarchiver cannotDecodeObjectOfClassName:(NSString *)name originalClasses:(NSArray *)classNames

    Parameters

    unarchiver

    An unarchiver for which the receiver is the delegate.

    name

    The name of the class of an object unarchiver is trying to decode.

    classNames

    An array describing the class hierarchy of the encoded object, where the first element is the class name string of the encoded object, the second element is the class name of its immediate superclass, and so on.

    Return Value

    The class unarchiver should use in place of the class named name.

    Discussion

    The delegate may, for example, load some code to introduce the class to the runtime and return the class, or substitute a different class object. If the delegate returns nil, unarchiving aborts and the method raises an NSInvalidUnarchiveOperationException.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Informs the delegate that a given object has been decoded.

    Declaration

    Swift

    optional func unarchiver(_ unarchiver: NSKeyedUnarchiver, didDecodeObject object: AnyObject?) -> AnyObject?

    Objective-C

    - (id)unarchiver:(NSKeyedUnarchiver *)unarchiver didDecodeObject:(id)object

    Parameters

    unarchiver

    An unarchiver for which the receiver is the delegate.

    object

    The object that has been decoded. object may be nil.

    Return Value

    The object to use in place of object. The delegate can either return object or return a different object to replace the decoded one. If the delegate returns nil, the decoded value will be unchanged (that is, the original object will be decoded).

    Discussion

    This method is called after object has been sent initWithCoder: and awakeAfterUsingCoder:.

    The delegate may use this method to keep track of the decoded objects.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Informs the delegate that one object is being substituted for another.

    Declaration

    Swift

    optional func unarchiver(_ unarchiver: NSKeyedUnarchiver, willReplaceObject object: AnyObject, withObject newObject: AnyObject)

    Objective-C

    - (void)unarchiver:(NSKeyedUnarchiver *)unarchiver willReplaceObject:(id)object withObject:(id)newObject

    Parameters

    unarchiver

    An unarchiver for which the receiver is the delegate.

    object

    An object in the archive.

    newObject

    The object with which unarchiver will replace object.

    Discussion

    This method is called even when the delegate itself is doing, or has done, the substitution with unarchiver:didDecodeObject:.

    The delegate may use this method if it is keeping track of the encoded or decoded objects.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Notifies the delegate that decoding has finished.

    Declaration

    Swift

    optional func unarchiverDidFinish(_ unarchiver: NSKeyedUnarchiver)

    Objective-C

    - (void)unarchiverDidFinish:(NSKeyedUnarchiver *)unarchiver

    Parameters

    unarchiver

    An unarchiver for which the receiver is the delegate.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Notifies the delegate that decoding is about to finish.

    Declaration

    Swift

    optional func unarchiverWillFinish(_ unarchiver: NSKeyedUnarchiver)

    Objective-C

    - (void)unarchiverWillFinish:(NSKeyedUnarchiver *)unarchiver

    Parameters

    unarchiver

    An unarchiver for which the receiver is the delegate.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.