Contents

decodeObject(of:forKey:)

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

Declaration

@nonobjc func decodeObject(of classes: [AnyClass]?, forKey key: String) -> Any?

Parameters

  • classes:

    An array of expected classes that the object being decoded should match at least one of.

  • key:

    The key indicating the member to decode.

Return Value

The decoded object, or nil if decoding fails.

Discussion

This method is equivalent to decodeObject(of:forKey:), but accepts a set of classes that the decoded object can match. If requiresSecureCoding is true, the decoded object’s class must be a member of the classes parameter, or a sublcass of a member.

See Also

Decoding Top-Level Objects