decodeTopLevelObject(of:forKey:)
Decode an object as one of several expected types, failing if the archived type does not match.
Declaration
func decodeTopLevelObject<DecodedObjectType>(of cls: DecodedObjectType.Type, forKey key: String) throws -> DecodedObjectType? where DecodedObjectType : NSObject, DecodedObjectType : NSCodingParameters
- cls:
The expected class of the object being decoded.
- key:
The key indicating the member to decode.
Return Value
The decoded object, or nil if decoding fails.
Discussion
If the coder responds true to requiresSecureCoding, then the coder calls failWithError(_:) in either the following cases:
The class indicated by
clsdoes not implement NSSecureCoding.The unarchived class does not match
cls, nor do any of its superclasses.
If the coder does not require secure coding, it ignores the cls parameter and does not check the decoded object.