decodeTopLevelObject(of:forKey:)
Decode an object as one of several expected types, failing if the archived type does not match.
Declaration
@nonobjc func decodeTopLevelObject(of classes: [AnyClass]?, forKey key: String) throws -> 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 allows you to specify 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.